feat: if dev mode is enabled store jwt to local storage and fetch it as needed
This commit is contained in:
parent
e6d296d6af
commit
740d276071
|
@ -39,9 +39,19 @@ export interface UpdatePasswordFormRequest extends UpdatePasswordFormTypes {
|
||||||
|
|
||||||
export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => {
|
export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => {
|
||||||
const maybeSetupAuth = (): void => {
|
const maybeSetupAuth = (): void => {
|
||||||
const jwt = sdk.account().jwtToken;
|
let jwt = sdk.account().jwtToken;
|
||||||
if (jwt) {
|
if (jwt) {
|
||||||
sdk.setAuthToken(jwt);
|
sdk.setAuthToken(jwt);
|
||||||
|
if (import.meta.env.DEV) {
|
||||||
|
localStorage.setItem("jwt", jwt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (import.meta.env.DEV) {
|
||||||
|
let jwt = localStorage.getItem("jwt");
|
||||||
|
if (jwt) {
|
||||||
|
sdk.setAuthToken(jwt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -100,6 +110,8 @@ export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => {
|
||||||
password: params.password,
|
password: params.password,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
maybeSetupAuth();
|
||||||
|
|
||||||
return handleResponse({
|
return handleResponse({
|
||||||
ret, redirectToSuccess: "/dashboard", redirectToError: "/login", successCb: () => {
|
ret, redirectToSuccess: "/dashboard", redirectToError: "/login", successCb: () => {
|
||||||
sdk.setAuthToken(sdk.account().jwtToken);
|
sdk.setAuthToken(sdk.account().jwtToken);
|
||||||
|
@ -113,11 +125,20 @@ export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => {
|
||||||
|
|
||||||
async logout(params: any): Promise<AuthActionResponse> {
|
async logout(params: any): Promise<AuthActionResponse> {
|
||||||
let ret = await sdk.account().logout();
|
let ret = await sdk.account().logout();
|
||||||
|
|
||||||
|
if (ret){
|
||||||
|
if (import.meta.env.DEV) {
|
||||||
|
localStorage.removeItem("jwt");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return handleResponse({ret, redirectToSuccess: "/login"});
|
return handleResponse({ret, redirectToSuccess: "/login"});
|
||||||
},
|
},
|
||||||
|
|
||||||
async check(params?: any): Promise<CheckResponse> {
|
async check(params?: any): Promise<CheckResponse> {
|
||||||
|
maybeSetupAuth();
|
||||||
const ret = await sdk.account().ping();
|
const ret = await sdk.account().ping();
|
||||||
|
maybeSetupAuth();
|
||||||
|
|
||||||
return handleCheckResponse({ret, redirectToError: "/login", successCb: maybeSetupAuth});
|
return handleCheckResponse({ret, redirectToError: "/login", successCb: maybeSetupAuth});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue