Skip to content

Commit

Permalink
Refactor AuthStatus type
Browse files Browse the repository at this point in the history
  • Loading branch information
tomrf1 committed Jan 27, 2025
1 parent 0e0f77b commit 1d5b862
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
9 changes: 3 additions & 6 deletions dotcom-rendering/src/components/TopBarMyAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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';
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion dotcom-rendering/src/lib/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export type SignedInWithOkta = {
};

export type AuthStatus =
| { kind: 'Pending' }
| SignedOutWithCookies
| SignedInWithCookies
| SignedOutWithOkta
Expand Down
6 changes: 4 additions & 2 deletions dotcom-rendering/src/lib/useAuthStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -25,8 +27,8 @@ export const useIsSignedIn = (): boolean | 'Pending' => {
}
};

export const useAuthStatus = (): AuthStatus => {
const [authStatus, setAuthStatus] = useState<AuthStatus>({
export const useAuthStatus = (): AuthStatusOrPending => {
const [authStatus, setAuthStatus] = useState<AuthStatusOrPending>({
kind: 'Pending',
});

Expand Down

0 comments on commit 1d5b862

Please sign in to comment.