Skip to content

Commit

Permalink
Merge pull request #564 from lifeomic/fix-set-login-flag
Browse files Browse the repository at this point in the history
fix: set initial login flag so it gets set if already logged in
  • Loading branch information
bruce-glazier authored May 29, 2024
2 parents efc6c37 + 7a989a3 commit ee88f56
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
7 changes: 7 additions & 0 deletions src/common/LoggedInProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +28,8 @@ const LoggedOutStack = createNativeStackNavigator<NotLoggedInRootParamList>();
export const LoggedInProviders = ({ children }: LoggedInProvidersProps) => {
const auth = useAuth();
const { pushNotificationsConfig } = useDeveloperConfig();
const [priorLoginDetected, setLoginDetected] =
useStoredValue('loginDetected');

if (!auth.isLoggedIn && auth.loading) {
return (
Expand All @@ -50,6 +53,10 @@ export const LoggedInProviders = ({ children }: LoggedInProvidersProps) => {
);
}

if (!priorLoginDetected) {
setLoginDetected('detected');
}

return (
<InviteProvider>
<ActiveProjectContextProvider>
Expand Down
11 changes: 1 addition & 10 deletions src/hooks/useOAuthFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
Expand Down Expand Up @@ -79,7 +78,6 @@ export const OAuthContextProvider = ({
const pendingInvite = usePendingInvite();
const queryClient = useQueryClient();
const { skipInviteParams } = useDeveloperConfig();
const [_, setLoginDetected] = useStoredValue('loginDetected');

const authConfig = useMemo(
() =>
Expand Down Expand Up @@ -161,7 +159,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) {
Expand All @@ -173,13 +170,7 @@ export const OAuthContextProvider = ({
onFail?.(error);
}
},
[
authConfig,
clearAuthResult,
pendingInvite?.evc,
setLoginDetected,
storeAuthResult,
],
[authConfig, clearAuthResult, pendingInvite?.evc, storeAuthResult],
);

const refreshHandler = useCallback(
Expand Down

0 comments on commit ee88f56

Please sign in to comment.