From 1d5b8623221abe038ba68dddbd8ca090b8dd2e61 Mon Sep 17 00:00:00 2001 From: Tom Forbes Date: Mon, 27 Jan 2025 15:19:43 +0000 Subject: [PATCH] Refactor AuthStatus type --- dotcom-rendering/src/components/TopBarMyAccount.tsx | 9 +++------ dotcom-rendering/src/lib/identity.ts | 1 - dotcom-rendering/src/lib/useAuthStatus.ts | 6 ++++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/dotcom-rendering/src/components/TopBarMyAccount.tsx b/dotcom-rendering/src/components/TopBarMyAccount.tsx index 0720504129a..268ee759d46 100644 --- a/dotcom-rendering/src/components/TopBarMyAccount.tsx +++ b/dotcom-rendering/src/components/TopBarMyAccount.tsx @@ -14,11 +14,7 @@ import { import { useEffect, useState } from 'react'; import type { UserProfile } from '../lib/discussion'; import { getZIndex } from '../lib/getZIndex'; -import type { - AuthStatus, - SignedInWithCookies, - SignedInWithOkta, -} from '../lib/identity'; +import type { SignedInWithCookies, SignedInWithOkta } from '../lib/identity'; import { createAuthenticationEventParams } from '../lib/identity-component-event'; import { addNotificationsToDropdownLinks, @@ -27,6 +23,7 @@ import { import type { Notification } from '../lib/notification'; import { nestedOphanComponents } from '../lib/ophan-helpers'; import { useApi } from '../lib/useApi'; +import type { AuthStatusOrPending } from '../lib/useAuthStatus'; import { useBraze } from '../lib/useBraze'; import { palette as themePalette } from '../palette'; import ProfileIcon from '../static/icons/profile.svg'; @@ -40,7 +37,7 @@ interface MyAccountProps { idUrl: string; discussionApiUrl: string; idApiUrl: string; - authStatus: AuthStatus; + authStatus: AuthStatusOrPending; } // when SignedIn, authStatus can only be one of the two SignedIn states diff --git a/dotcom-rendering/src/lib/identity.ts b/dotcom-rendering/src/lib/identity.ts index 62af6877579..6f9419d9f9a 100644 --- a/dotcom-rendering/src/lib/identity.ts +++ b/dotcom-rendering/src/lib/identity.ts @@ -41,7 +41,6 @@ export type SignedInWithOkta = { }; export type AuthStatus = - | { kind: 'Pending' } | SignedOutWithCookies | SignedInWithCookies | SignedOutWithOkta diff --git a/dotcom-rendering/src/lib/useAuthStatus.ts b/dotcom-rendering/src/lib/useAuthStatus.ts index 194a6f340b0..c8c80d7e966 100644 --- a/dotcom-rendering/src/lib/useAuthStatus.ts +++ b/dotcom-rendering/src/lib/useAuthStatus.ts @@ -6,6 +6,8 @@ import { getSignedInStatusWithOkta, } from './identity'; +export type AuthStatusOrPending = AuthStatus | { kind: 'Pending' }; + /** * A hook to find out if a user is signed in. * Returns `'Pending'` until status is known. @@ -25,8 +27,8 @@ export const useIsSignedIn = (): boolean | 'Pending' => { } }; -export const useAuthStatus = (): AuthStatus => { - const [authStatus, setAuthStatus] = useState({ +export const useAuthStatus = (): AuthStatusOrPending => { + const [authStatus, setAuthStatus] = useState({ kind: 'Pending', });