Improve authentication by extending timeouts and enhancing refresh handling

Extend loading timeout to 30s, remove onboarding progress from local storage clear, and remove invalid TOKEN_REFRESH_FAILED event handling.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 9203795e-937a-4306-b81d-b4d5c78c240e
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Event-Id: 7c308a4f-cdda-469f-b6dd-d39d0348d45c
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7c94b7a0-29c7-4f2e-94ef-44b2153872b7/9203795e-937a-4306-b81d-b4d5c78c240e/saoW2ee
Replit-Helium-Checkpoint-Created: true
This commit is contained in:
sirpiglr 2025-12-02 22:06:25 +00:00
commit 56ff597623

View file

@ -170,17 +170,18 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
let sessionRestored = false; let sessionRestored = false;
// Add timeout to ensure loading doesn't get stuck // Add timeout to ensure loading doesn't get stuck
// Increased from 3s to 5s to allow more time for session restoration after OAuth // Increased to 30s to allow more time for session restoration on slow networks
const loadingTimeout = setTimeout(() => { const loadingTimeout = setTimeout(() => {
console.log("Auth loading timeout - forcing loading to false"); console.log("Auth loading timeout - forcing loading to false");
if (!sessionRestored) { if (!sessionRestored) {
setLoading(false); setLoading(false);
} }
}, 5000); }, 30000);
if (!storageClearedRef.current && typeof window !== "undefined") { if (!storageClearedRef.current && typeof window !== "undefined") {
try { try {
// ONLY clear mock/demo data, NOT actual Supabase auth session // ONLY clear mock/demo data, NOT actual Supabase auth session
// NOTE: We no longer clear aethex_onboarding_progress_v1 here to preserve user progress
[ [
"mock_user", "mock_user",
"mock_profile", "mock_profile",
@ -188,7 +189,6 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
"demo_profiles", "demo_profiles",
"demo_posts", "demo_posts",
"demo_seed_v1", "demo_seed_v1",
"aethex_onboarding_progress_v1",
].forEach((key) => window.localStorage.removeItem(key)); ].forEach((key) => window.localStorage.removeItem(key));
// NOTE: We deliberately DO NOT clear: // NOTE: We deliberately DO NOT clear:
@ -276,26 +276,6 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
}, 50); }, 50);
} }
// Handle token refresh failures specifically
if (event === "TOKEN_REFRESH_FAILED") {
console.warn("Token refresh failed - clearing local session");
try {
clearClientAuthState();
} catch (e) {
/* ignore */
}
try {
aethexToast.error({
title: "Session expired",
description:
"Your session could not be refreshed and has been cleared. Please sign in again.",
});
} catch (e) {
/* ignore */
}
return;
}
// Show toast notifications for auth events // Show toast notifications for auth events
if (event === "SIGNED_IN") { if (event === "SIGNED_IN") {
aethexToast.success({ aethexToast.success({