From 7293cb0b5a5d572acd6b482fbfd11969e2bd0134 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 18 Mar 2024 17:25:49 -0400 Subject: [PATCH] refactor: switch to pulling the cookie from the account service after ping as ping now returns it in the response --- app/data/auth-provider.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/data/auth-provider.ts b/app/data/auth-provider.ts index 55188b6..7a96734 100644 --- a/app/data/auth-provider.ts +++ b/app/data/auth-provider.ts @@ -8,7 +8,6 @@ import type { // @ts-ignore } from "@refinedev/core/dist/interfaces/bindings/auth" import {Sdk} from "@lumeweb/portal-sdk"; -import Cookies from 'universal-cookie'; import type {AccountInfoResponse} from "@lumeweb/portal-sdk"; export type AuthFormRequest = { @@ -91,15 +90,16 @@ export class PortalAuthProvider implements RequiredAuthProvider { } async check(params?: any): Promise { - this.maybeSetupAuth(); - const ret = await this._sdk.account().ping(); + if(ret){ + this.maybeSetupAuth(); + } + return {authenticated: ret, redirectTo: ret ? undefined : "/login"}; } async onError(error: any): Promise { - const cookies = new Cookies(); return {logout: true}; } @@ -144,10 +144,9 @@ export class PortalAuthProvider implements RequiredAuthProvider { } maybeSetupAuth(): void { - const cookies = new Cookies(); - const jwtCookie = cookies.get('auth_token'); - if (jwtCookie) { - this._sdk.setAuthToken(jwtCookie); + const jwt = this._sdk.account().jwtToken + if (jwt) { + this._sdk.setAuthToken(jwt); } } }