Skip to content

Commit

Permalink
fix(app): automatically prompt to login back when access changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rhahao committed Nov 25, 2024
1 parent 210bd96 commit e16226c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/features/app_start/vip/startup/useStartup.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useState } from 'react';
import { useSearchParams } from 'react-router-dom';
import { useRecoilValue, useSetRecoilState } from 'recoil';
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
import {
congIDState,
congregationCreateStepState,
Expand All @@ -19,7 +19,6 @@ import {
setIsEmailLinkAuthenticate,
setIsEncryptionCodeOpen,
setIsSetup,
setIsUserSignIn,
setUserMfaVerify,
} from '@services/recoil/app';
import {
Expand All @@ -37,14 +36,15 @@ import { userSignOut } from '@services/firebase/auth';
const useStartup = () => {
const [searchParams] = useSearchParams();

const [isUserSignIn, setIsUserSignIn] = useRecoilState(isUserSignInState);

const setCookiesConsent = useSetRecoilState(cookiesConsentState);
const setCongCreate = useSetRecoilState(isCongAccountCreateState);
const setCurrentStep = useSetRecoilState(congregationCreateStepState);
const setCongID = useSetRecoilState(congIDState);

const isEmailLinkAuth = useRecoilValue(isEmailLinkAuthenticateState);
const isEmailAuth = useRecoilValue(isEmailAuthState);
const isUserSignIn = useRecoilValue(isUserSignInState);
const isUserMfaVerify = useRecoilValue(isUserMfaVerifyState);
const isUserAccountCreated = useRecoilValue(isUserAccountCreatedState);
const isOfflineOverride = useRecoilValue(offlineOverrideState);
Expand All @@ -63,7 +63,7 @@ const useStartup = () => {
const showSignin = useCallback(() => {
setIsUserSignIn(true);
setUserMfaVerify(false);
}, []);
}, [setIsUserSignIn]);

const runStartupCheck = useCallback(async () => {
setIsLoading(true);
Expand Down Expand Up @@ -198,7 +198,7 @@ const useStartup = () => {
}

if (cookiesConsent && isStart) runStartupCheck();
}, [cookiesConsent, isStart, runStartupCheck]);
}, [setIsUserSignIn, cookiesConsent, isStart, runStartupCheck]);

return {
isEmailAuth,
Expand Down
1 change: 1 addition & 0 deletions src/features/persons/button_actions/useButtonActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const useButtonActions = () => {
icon: <IconCheckCircle color="var(--white)" />,
});

navigate(-1);
navigate('/persons');
}

Expand Down
14 changes: 14 additions & 0 deletions src/hooks/useUserAutoLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
isAppLoadState,
isMFAEnabledState,
isOnlineState,
isSetupState,
offlineOverrideState,
userIDState,
} from '@states/app';
import { apiValidateMe } from '@services/api/user';
Expand Down Expand Up @@ -40,6 +42,9 @@ const useUserAutoLogin = () => {
const setCongConnected = useSetRecoilState(congAccountConnectedState);
const setUserID = useSetRecoilState(userIDState);
const setIsMFAEnabled = useSetRecoilState(isMFAEnabledState);
const setOfflineOverride = useSetRecoilState(offlineOverrideState);
const setIsSetup = useSetRecoilState(isSetupState);
const setIsAppLoad = useSetRecoilState(isAppLoadState);

const isOnline = useRecoilValue(isOnlineState);
const apiHost = useRecoilValue(apiHostState);
Expand Down Expand Up @@ -165,6 +170,12 @@ const useUserAutoLogin = () => {
await userSignOut();

setCongConnected(false);
setOfflineOverride(true);

setTimeout(() => {
setIsAppLoad(true);
setIsSetup(true);
}, 2000);

return;
}
Expand Down Expand Up @@ -224,6 +235,9 @@ const useUserAutoLogin = () => {
setCongID,
setUserID,
setIsMFAEnabled,
setIsAppLoad,
setIsSetup,
setOfflineOverride,
]);

useEffect(() => {
Expand Down

0 comments on commit e16226c

Please sign in to comment.