refactor: switch to pulling the cookie from the account service after ping as ping now returns it in the response
This commit is contained in:
parent
ba374a851c
commit
7293cb0b5a
|
@ -8,7 +8,6 @@ import type {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
} from "@refinedev/core/dist/interfaces/bindings/auth"
|
} from "@refinedev/core/dist/interfaces/bindings/auth"
|
||||||
import {Sdk} from "@lumeweb/portal-sdk";
|
import {Sdk} from "@lumeweb/portal-sdk";
|
||||||
import Cookies from 'universal-cookie';
|
|
||||||
import type {AccountInfoResponse} from "@lumeweb/portal-sdk";
|
import type {AccountInfoResponse} from "@lumeweb/portal-sdk";
|
||||||
|
|
||||||
export type AuthFormRequest = {
|
export type AuthFormRequest = {
|
||||||
|
@ -91,15 +90,16 @@ export class PortalAuthProvider implements RequiredAuthProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
async check(params?: any): Promise<CheckResponse> {
|
async check(params?: any): Promise<CheckResponse> {
|
||||||
this.maybeSetupAuth();
|
|
||||||
|
|
||||||
const ret = await this._sdk.account().ping();
|
const ret = await this._sdk.account().ping();
|
||||||
|
|
||||||
|
if(ret){
|
||||||
|
this.maybeSetupAuth();
|
||||||
|
}
|
||||||
|
|
||||||
return {authenticated: ret, redirectTo: ret ? undefined : "/login"};
|
return {authenticated: ret, redirectTo: ret ? undefined : "/login"};
|
||||||
}
|
}
|
||||||
|
|
||||||
async onError(error: any): Promise<OnErrorResponse> {
|
async onError(error: any): Promise<OnErrorResponse> {
|
||||||
const cookies = new Cookies();
|
|
||||||
return {logout: true};
|
return {logout: true};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,10 +144,9 @@ export class PortalAuthProvider implements RequiredAuthProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
maybeSetupAuth(): void {
|
maybeSetupAuth(): void {
|
||||||
const cookies = new Cookies();
|
const jwt = this._sdk.account().jwtToken
|
||||||
const jwtCookie = cookies.get('auth_token');
|
if (jwt) {
|
||||||
if (jwtCookie) {
|
this._sdk.setAuthToken(jwt);
|
||||||
this._sdk.setAuthToken(jwtCookie);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue