fix and update
This commit is contained in:
@@ -16,17 +16,15 @@ import {
|
||||
buildAuthDevicePayload,
|
||||
IdentifyResponse,
|
||||
getApiErrorMessage,
|
||||
isApiGatewayReady,
|
||||
isPinRequiredError,
|
||||
OtpSendResponse,
|
||||
PasswordlessAuthResponse,
|
||||
PinVerificationResponse,
|
||||
PublicUser,
|
||||
refreshAuthSession,
|
||||
resetApiGatewayWarmup,
|
||||
resetPinRequiredNotification,
|
||||
scheduleFedcmSessionSync,
|
||||
setPinRequiredHandler,
|
||||
syncFedcmSession
|
||||
} from '@/lib/api';
|
||||
import { useToast } from './toast-provider';
|
||||
import { PinLockModal } from './pin-lock-modal';
|
||||
@@ -94,9 +92,7 @@ function applySessionState(
|
||||
setters.activatePinLock(session.sessionId ?? '');
|
||||
} else {
|
||||
setters.clearPinLock();
|
||||
void ensureApiGatewayReady().then(() => {
|
||||
void syncFedcmSession();
|
||||
});
|
||||
scheduleFedcmSessionSync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,16 +159,11 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
cacheUserProfile(auth.user);
|
||||
setHasStoredSession(true);
|
||||
clearPinLock();
|
||||
initialBootstrapDoneRef.current = false;
|
||||
resetApiGatewayWarmup();
|
||||
setIsLoading(true);
|
||||
void ensureApiGatewayReady().finally(() => {
|
||||
initialBootstrapDoneRef.current = true;
|
||||
setIsLoading(false);
|
||||
if (auth.pinVerified !== false) {
|
||||
void syncFedcmSession(auth.accessToken);
|
||||
}
|
||||
});
|
||||
initialBootstrapDoneRef.current = true;
|
||||
setIsLoading(false);
|
||||
if (auth.pinVerified !== false) {
|
||||
scheduleFedcmSessionSync(auth.accessToken, 2000);
|
||||
}
|
||||
},
|
||||
[clearPinLock]
|
||||
);
|
||||
@@ -182,7 +173,6 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
window.localStorage.removeItem(AUTH_REFRESH_KEY);
|
||||
window.localStorage.removeItem(AUTH_SESSION_KEY);
|
||||
window.localStorage.removeItem(AUTH_USER_CACHE_KEY);
|
||||
resetApiGatewayWarmup();
|
||||
initialBootstrapDoneRef.current = false;
|
||||
setToken(null);
|
||||
setUser(null);
|
||||
@@ -210,7 +200,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
const isInitialBootstrap = !initialBootstrapDoneRef.current;
|
||||
if (isInitialBootstrap) {
|
||||
setIsLoading(true);
|
||||
resetApiGatewayWarmup();
|
||||
await ensureApiGatewayReady();
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -273,17 +263,6 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
if (message) showToast(message);
|
||||
logout();
|
||||
} finally {
|
||||
const hasSession = Boolean(
|
||||
window.localStorage.getItem(AUTH_TOKEN_KEY) || window.localStorage.getItem(AUTH_REFRESH_KEY)
|
||||
);
|
||||
if (hasSession && isInitialBootstrap) {
|
||||
const bootstrapDeadline = Date.now() + 120_000;
|
||||
while (!isApiGatewayReady() && Date.now() < bootstrapDeadline) {
|
||||
await ensureApiGatewayReady(true);
|
||||
if (isApiGatewayReady()) break;
|
||||
await new Promise((resolve) => setTimeout(resolve, 800));
|
||||
}
|
||||
}
|
||||
if (isInitialBootstrap) {
|
||||
initialBootstrapDoneRef.current = true;
|
||||
setIsLoading(false);
|
||||
|
||||
Reference in New Issue
Block a user