Admin panel init (#8742)
WIP Related issues - #7090 #8547 Master issue - #4499 --------- Co-authored-by: Félix Malfait <felix@twenty.com>
This commit is contained in:
@ -69,6 +69,49 @@ export const useAuth = () => {
|
||||
|
||||
const setDateTimeFormat = useSetRecoilState(dateTimeFormatState);
|
||||
|
||||
const clearSession = useRecoilCallback(
|
||||
({ snapshot }) =>
|
||||
async () => {
|
||||
const emptySnapshot = snapshot_UNSTABLE();
|
||||
const iconsValue = snapshot.getLoadable(iconsState).getValue();
|
||||
const authProvidersValue = snapshot
|
||||
.getLoadable(authProvidersState)
|
||||
.getValue();
|
||||
const billing = snapshot.getLoadable(billingState).getValue();
|
||||
const isSignInPrefilled = snapshot
|
||||
.getLoadable(isSignInPrefilledState)
|
||||
.getValue();
|
||||
const supportChat = snapshot.getLoadable(supportChatState).getValue();
|
||||
const isDebugMode = snapshot.getLoadable(isDebugModeState).getValue();
|
||||
const captchaProvider = snapshot
|
||||
.getLoadable(captchaProviderState)
|
||||
.getValue();
|
||||
const clientConfigApiStatus = snapshot
|
||||
.getLoadable(clientConfigApiStatusState)
|
||||
.getValue();
|
||||
const isCurrentUserLoaded = snapshot
|
||||
.getLoadable(isCurrentUserLoadedState)
|
||||
.getValue();
|
||||
const initialSnapshot = emptySnapshot.map(({ set }) => {
|
||||
set(iconsState, iconsValue);
|
||||
set(authProvidersState, authProvidersValue);
|
||||
set(billingState, billing);
|
||||
set(isSignInPrefilledState, isSignInPrefilled);
|
||||
set(supportChatState, supportChat);
|
||||
set(isDebugModeState, isDebugMode);
|
||||
set(captchaProviderState, captchaProvider);
|
||||
set(clientConfigApiStatusState, clientConfigApiStatus);
|
||||
set(isCurrentUserLoadedState, isCurrentUserLoaded);
|
||||
return undefined;
|
||||
});
|
||||
goToRecoilSnapshot(initialSnapshot);
|
||||
await client.clearStore();
|
||||
sessionStorage.clear();
|
||||
localStorage.clear();
|
||||
},
|
||||
[client, goToRecoilSnapshot],
|
||||
);
|
||||
|
||||
const handleChallenge = useCallback(
|
||||
async (email: string, password: string, captchaToken?: string) => {
|
||||
const challengeResult = await challenge({
|
||||
@ -212,51 +255,9 @@ export const useAuth = () => {
|
||||
[handleChallenge, handleVerify, setIsVerifyPendingState],
|
||||
);
|
||||
|
||||
const handleSignOut = useRecoilCallback(
|
||||
({ snapshot }) =>
|
||||
async () => {
|
||||
const emptySnapshot = snapshot_UNSTABLE();
|
||||
const iconsValue = snapshot.getLoadable(iconsState).getValue();
|
||||
const authProvidersValue = snapshot
|
||||
.getLoadable(authProvidersState)
|
||||
.getValue();
|
||||
const billing = snapshot.getLoadable(billingState).getValue();
|
||||
const isSignInPrefilled = snapshot
|
||||
.getLoadable(isSignInPrefilledState)
|
||||
.getValue();
|
||||
const supportChat = snapshot.getLoadable(supportChatState).getValue();
|
||||
const isDebugMode = snapshot.getLoadable(isDebugModeState).getValue();
|
||||
const captchaProvider = snapshot
|
||||
.getLoadable(captchaProviderState)
|
||||
.getValue();
|
||||
const clientConfigApiStatus = snapshot
|
||||
.getLoadable(clientConfigApiStatusState)
|
||||
.getValue();
|
||||
const isCurrentUserLoaded = snapshot
|
||||
.getLoadable(isCurrentUserLoadedState)
|
||||
.getValue();
|
||||
|
||||
const initialSnapshot = emptySnapshot.map(({ set }) => {
|
||||
set(iconsState, iconsValue);
|
||||
set(authProvidersState, authProvidersValue);
|
||||
set(billingState, billing);
|
||||
set(isSignInPrefilledState, isSignInPrefilled);
|
||||
set(supportChatState, supportChat);
|
||||
set(isDebugModeState, isDebugMode);
|
||||
set(captchaProviderState, captchaProvider);
|
||||
set(clientConfigApiStatusState, clientConfigApiStatus);
|
||||
set(isCurrentUserLoadedState, isCurrentUserLoaded);
|
||||
return undefined;
|
||||
});
|
||||
|
||||
goToRecoilSnapshot(initialSnapshot);
|
||||
|
||||
await client.clearStore();
|
||||
sessionStorage.clear();
|
||||
localStorage.clear();
|
||||
},
|
||||
[client, goToRecoilSnapshot],
|
||||
);
|
||||
const handleSignOut = useCallback(async () => {
|
||||
await clearSession();
|
||||
}, [clearSession]);
|
||||
|
||||
const handleCredentialsSignUp = useCallback(
|
||||
async (
|
||||
@ -340,7 +341,7 @@ export const useAuth = () => {
|
||||
verify: handleVerify,
|
||||
|
||||
checkUserExists: { checkUserExistsData, checkUserExistsQuery },
|
||||
|
||||
clearSession,
|
||||
signOut: handleSignOut,
|
||||
signUpWithCredentials: handleCredentialsSignUp,
|
||||
signInWithCredentials: handleCrendentialsSignIn,
|
||||
|
||||
Reference in New Issue
Block a user