fix: Prevent token race conditions by pre-saving access/refresh tokens to localStorage before NextAuth signIn and refining logout token clearing.
This commit is contained in:
@@ -39,9 +39,14 @@ function TokenSync() {
|
||||
hasInitialized.current = true;
|
||||
}
|
||||
} else if (status === "unauthenticated") {
|
||||
// Clear tokens when logged out
|
||||
localStorage.removeItem("accessToken");
|
||||
localStorage.removeItem("refreshToken");
|
||||
// Only clear tokens if a logout is explicitly in progress.
|
||||
// Don't clear during normal page loads or brief unauthenticated flickers,
|
||||
// as the login page saves tokens to localStorage before signIn completes.
|
||||
const loggingOut = localStorage.getItem("isLoggingOut") === "true";
|
||||
if (loggingOut) {
|
||||
localStorage.removeItem("accessToken");
|
||||
localStorage.removeItem("refreshToken");
|
||||
}
|
||||
hasInitialized.current = false;
|
||||
}
|
||||
}, [session, status]);
|
||||
|
||||
Reference in New Issue
Block a user