From 5906da08fe8396a21a3d71898248e730abab62ec Mon Sep 17 00:00:00 2001 From: Bruce Glazier Date: Tue, 28 May 2024 10:28:30 -0400 Subject: [PATCH 1/2] fix: set initial login flag so it gets set if already logged in --- src/common/LoggedInProviders.tsx | 7 +++++++ src/hooks/useOAuthFlow.tsx | 10 +--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/common/LoggedInProviders.tsx b/src/common/LoggedInProviders.tsx index 8726efa6..a8caa6de 100644 --- a/src/common/LoggedInProviders.tsx +++ b/src/common/LoggedInProviders.tsx @@ -17,6 +17,7 @@ import { ActivityIndicatorView } from '../components/ActivityIndicatorView'; import { InviteProvider } from '../components/Invitations/InviteProvider'; import { t } from 'i18next'; import AppConfigSwitcher from '../components/AppConfigSwitcher'; +import { useStoredValue } from '../hooks/useStoredValue'; export type LoggedInProvidersProps = { children?: React.ReactNode; @@ -27,6 +28,8 @@ const LoggedOutStack = createNativeStackNavigator(); export const LoggedInProviders = ({ children }: LoggedInProvidersProps) => { const auth = useAuth(); const { pushNotificationsConfig } = useDeveloperConfig(); + const [priorLoginDetected, setLoginDetected] = + useStoredValue('loginDetected'); if (!auth.isLoggedIn && auth.loading) { return ( @@ -50,6 +53,10 @@ export const LoggedInProviders = ({ children }: LoggedInProvidersProps) => { ); } + if (!priorLoginDetected) { + setLoginDetected('detected'); + } + return ( diff --git a/src/hooks/useOAuthFlow.tsx b/src/hooks/useOAuthFlow.tsx index aa21ce9e..0a1ae266 100644 --- a/src/hooks/useOAuthFlow.tsx +++ b/src/hooks/useOAuthFlow.tsx @@ -79,7 +79,6 @@ export const OAuthContextProvider = ({ const pendingInvite = usePendingInvite(); const queryClient = useQueryClient(); const { skipInviteParams } = useDeveloperConfig(); - const [_, setLoginDetected] = useStoredValue('loginDetected'); const authConfig = useMemo( () => @@ -161,7 +160,6 @@ export const OAuthContextProvider = ({ try { const result = await authorize(authConfig); await storeAuthResult(result); - setLoginDetected('detected'); _sdkAnalyticsEvent.track('Login', { usedInvite: !!pendingInvite?.evc }); onSuccess?.(result); } catch (error) { @@ -173,13 +171,7 @@ export const OAuthContextProvider = ({ onFail?.(error); } }, - [ - authConfig, - clearAuthResult, - pendingInvite?.evc, - setLoginDetected, - storeAuthResult, - ], + [authConfig, clearAuthResult, pendingInvite?.evc, storeAuthResult], ); const refreshHandler = useCallback( From 7a989a34480e7da8fbad4ba8dfb79ee6f2193239 Mon Sep 17 00:00:00 2001 From: Bruce Glazier Date: Tue, 28 May 2024 10:34:30 -0400 Subject: [PATCH 2/2] chore: remove unused import --- src/hooks/useOAuthFlow.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/hooks/useOAuthFlow.tsx b/src/hooks/useOAuthFlow.tsx index 0a1ae266..e29c2bde 100644 --- a/src/hooks/useOAuthFlow.tsx +++ b/src/hooks/useOAuthFlow.tsx @@ -17,7 +17,6 @@ import { usePendingInvite } from '../components/Invitations/InviteProvider'; import { useQueryClient } from '@tanstack/react-query'; import { _sdkAnalyticsEvent } from '../common/Analytics'; import { useDeveloperConfig } from './useDeveloperConfig'; -import { useStoredValue } from './useStoredValue'; export interface OAuthConfig { login: (params: LoginParams) => Promise;