Move API_ORIGIN into constants.js
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
|
||||
import { ROLES } from '../constants.js';
|
||||
import { ROLES, API_ORIGIN } from '../constants.js';
|
||||
import { fetcher } from 'pankow';
|
||||
|
||||
function create() {
|
||||
const accessToken = localStorage.token;
|
||||
const origin = import.meta.env.VITE_API_ORIGIN || window.location.origin;
|
||||
|
||||
return {
|
||||
name: 'ProfileModel',
|
||||
async logout() {
|
||||
// destroy oidc session in the spirit of true SSO
|
||||
await fetcher.del(`${origin}/api/v1/oidc/sessions`, { access_token: accessToken });
|
||||
await fetcher.del(`${API_ORIGIN}/api/v1/oidc/sessions`, { access_token: accessToken });
|
||||
|
||||
localStorage.removeItem('token');
|
||||
|
||||
@@ -19,7 +18,7 @@ function create() {
|
||||
async get() {
|
||||
let error, result;
|
||||
try {
|
||||
result = await fetcher.get(`${origin}/api/v1/profile`, { access_token: accessToken });
|
||||
result = await fetcher.get(`${API_ORIGIN}/api/v1/profile`, { access_token: accessToken });
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
@@ -39,7 +38,7 @@ function create() {
|
||||
async setPassword(password, newPassword) {
|
||||
let error, result;
|
||||
try {
|
||||
result = await fetcher.post(`${origin}/api/v1/profile/password`, { password, newPassword }, { access_token: accessToken });
|
||||
result = await fetcher.post(`${API_ORIGIN}/api/v1/profile/password`, { password, newPassword }, { access_token: accessToken });
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
@@ -52,7 +51,7 @@ function create() {
|
||||
async setDisplayName(displayName) {
|
||||
let error, result;
|
||||
try {
|
||||
result = await fetcher.post(`${origin}/api/v1/profile/display_name`, { displayName }, { access_token: accessToken });
|
||||
result = await fetcher.post(`${API_ORIGIN}/api/v1/profile/display_name`, { displayName }, { access_token: accessToken });
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
@@ -65,7 +64,7 @@ function create() {
|
||||
async setEmail(email, password) {
|
||||
let error, result;
|
||||
try {
|
||||
result = await fetcher.post(`${origin}/api/v1/profile/email`, { email, password }, { access_token: accessToken });
|
||||
result = await fetcher.post(`${API_ORIGIN}/api/v1/profile/email`, { email, password }, { access_token: accessToken });
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
@@ -78,7 +77,7 @@ function create() {
|
||||
async setFallbackEmail(fallbackEmail, password) {
|
||||
let error, result;
|
||||
try {
|
||||
result = await fetcher.post(`${origin}/api/v1/profile/fallback_email`, { fallbackEmail, password }, { access_token: accessToken });
|
||||
result = await fetcher.post(`${API_ORIGIN}/api/v1/profile/fallback_email`, { fallbackEmail, password }, { access_token: accessToken });
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
@@ -91,7 +90,7 @@ function create() {
|
||||
async setLanguage(language) {
|
||||
let error, result;
|
||||
try {
|
||||
result = await fetcher.post(`${origin}/api/v1/profile/language`, { language }, { access_token: accessToken });
|
||||
result = await fetcher.post(`${API_ORIGIN}/api/v1/profile/language`, { language }, { access_token: accessToken });
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
@@ -107,7 +106,7 @@ function create() {
|
||||
|
||||
let error, result;
|
||||
try {
|
||||
result = await fetcher.post(`${origin}/api/v1/profile/avatar`, fd, { access_token: accessToken });
|
||||
result = await fetcher.post(`${API_ORIGIN}/api/v1/profile/avatar`, fd, { access_token: accessToken });
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
@@ -120,7 +119,7 @@ function create() {
|
||||
async sendPasswordReset(identifier) {
|
||||
let error, result;
|
||||
try {
|
||||
result = await fetcher.post(`${origin}/api/v1/auth/password_reset_request`, { identifier }, { access_token: accessToken });
|
||||
result = await fetcher.post(`${API_ORIGIN}/api/v1/auth/password_reset_request`, { identifier }, { access_token: accessToken });
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
@@ -133,7 +132,7 @@ function create() {
|
||||
async setTwoFASecret() {
|
||||
let error, result;
|
||||
try {
|
||||
result = await fetcher.post(`${origin}/api/v1/profile/twofactorauthentication_secret`, {}, { access_token: accessToken });
|
||||
result = await fetcher.post(`${API_ORIGIN}/api/v1/profile/twofactorauthentication_secret`, {}, { access_token: accessToken });
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
@@ -144,7 +143,7 @@ function create() {
|
||||
async enableTwoFA(totpToken) {
|
||||
let error, result;
|
||||
try {
|
||||
result = await fetcher.post(`${origin}/api/v1/profile/twofactorauthentication_enable`, { totpToken }, { access_token: accessToken });
|
||||
result = await fetcher.post(`${API_ORIGIN}/api/v1/profile/twofactorauthentication_enable`, { totpToken }, { access_token: accessToken });
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
@@ -155,7 +154,7 @@ function create() {
|
||||
async disableTwoFA(password) {
|
||||
let error, result;
|
||||
try {
|
||||
result = await fetcher.post(`${origin}/api/v1/profile/twofactorauthentication_disable`, { password }, { access_token: accessToken });
|
||||
result = await fetcher.post(`${API_ORIGIN}/api/v1/profile/twofactorauthentication_disable`, { password }, { access_token: accessToken });
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user