From bec75e63eef7adf9a4f0ae4270d4b0fb2543e8ca Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 20 Mar 2024 15:26:24 -0400 Subject: [PATCH] refactor: fix handling of check by creating a handleCheckResponse wrapper to translate success to authenticated --- app/data/auth-provider.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/data/auth-provider.ts b/app/data/auth-provider.ts index 25acbc6..d6d38eb 100644 --- a/app/data/auth-provider.ts +++ b/app/data/auth-provider.ts @@ -54,6 +54,10 @@ export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => { successCb?: () => void; } + interface CheckResponseResult extends ResponseResult { + authenticated?: boolean; + } + const handleResponse = (result: ResponseResult): AuthActionResponse => { if (result.ret) { if (result.ret instanceof Error) { @@ -79,6 +83,17 @@ export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => { } } + const handleCheckResponse = (result: CheckResponseResult): CheckResponse => { + const response = handleResponse(result); + const success = response.success; + delete response.success; + + return { + ...response, + authenticated: success + } + } + return { async login(params: AuthFormRequest): Promise { const ret = await sdk.account().login({ @@ -105,7 +120,7 @@ export const createPortalAuthProvider = (sdk: Sdk): AuthProvider => { async check(params?: any): Promise { const ret = await sdk.account().ping(); - return handleResponse({ret, redirectToError: "/login", successCb: maybeSetupAuth}); + return handleCheckResponse({ret, redirectToError: "/login", successCb: maybeSetupAuth}); }, async onError(error: any): Promise {