Skip to content

Commit

Permalink
fix: ssr shift due to firstLoad
Browse files Browse the repository at this point in the history
  • Loading branch information
ilasw committed Nov 4, 2024
1 parent 5b6dc71 commit 540d67b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
10 changes: 5 additions & 5 deletions packages/shared/src/contexts/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { AccessToken, Boot, Visit } from '../lib/boot';
import { isCompanionActivated } from '../lib/element';
import { AuthTriggers, AuthTriggersType } from '../lib/auth';
import { Squad } from '../graphql/sources';
import { checkIsExtension, isNullOrUndefined } from '../lib/func';
import { checkIsExtension } from '../lib/func';

export interface LoginState {
trigger: AuthTriggersType;
Expand Down Expand Up @@ -103,7 +103,7 @@ export type AuthContextProviderProps = {
isFetched?: boolean;
isLegacyLogout?: boolean;
children?: ReactNode;
firstLoad?: boolean;
isAuthReady?: boolean;
} & Pick<
AuthContextData,
| 'getRedirectUri'
Expand Down Expand Up @@ -131,14 +131,14 @@ export const AuthContextProvider = ({
isLegacyLogout,
accessToken,
squads,
firstLoad,
isAuthReady,
}: AuthContextProviderProps): ReactElement => {
const [loginState, setLoginState] = useState<LoginState | null>(null);
const endUser = user && 'providers' in user ? user : null;
const referral = user?.referralId || user?.referrer;
const referralOrigin = user?.referralOrigin;

if (firstLoad === true && endUser && !endUser?.infoConfirmed) {
if (isAuthReady === true && endUser && !endUser?.infoConfirmed) {
logout(LogoutReason.IncomleteOnboarding);
}

Expand All @@ -149,7 +149,7 @@ export const AuthContextProvider = ({
return (
<AuthContext.Provider
value={{
isAuthReady: !isNullOrUndefined(firstLoad),
isAuthReady,
user: endUser,
isLoggedIn: !!endUser?.id,
referral: loginState?.referral ?? referral,
Expand Down
5 changes: 2 additions & 3 deletions packages/shared/src/contexts/BootProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ export const BootDataProvider = ({
placeholderData: initialData,
});

const isInitialFetch = !isFetched;
const isBootReady = isFetched && !isError;
const isBootReady = isFetched && !isError && !!bootData;
const loadedFromCache = !!bootData;
const { user, settings, alerts, notifications, squads } = bootData || {};

Expand Down Expand Up @@ -276,7 +275,7 @@ export const BootDataProvider = ({
isLegacyLogout={bootData?.isLegacyLogout}
accessToken={bootData?.accessToken}
squads={squads}
firstLoad={isInitialFetch}
isAuthReady={isBootReady}
>
<SettingsContextProvider
settings={settings}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('useJoinReferral hook', () => {
updateUser={jest.fn()}
tokenRefreshed={false}
isFetched
firstLoad={false}
isAuthReady={false}
>
{children}
</AuthContextProvider>
Expand Down

0 comments on commit 540d67b

Please sign in to comment.