fixes fixes fixes tenaancy

This commit is contained in:
IGNY8 VPS (Salman)
2025-12-09 02:43:51 +00:00
parent 92211f065b
commit 72d0b6b0fd
23 changed files with 1428 additions and 19 deletions

View File

@@ -118,6 +118,14 @@ export const useAuthStore = create<AuthState>()(
version: 0
};
localStorage.setItem('auth-storage', JSON.stringify(authState));
// CRITICAL: Also set tokens as separate items for API interceptor
if (newToken) {
localStorage.setItem('access_token', newToken);
}
if (newRefreshToken) {
localStorage.setItem('refresh_token', newRefreshToken);
}
} catch (e) {
console.warn('Failed to persist auth state to localStorage:', e);
}
@@ -229,6 +237,7 @@ export const useAuthStore = create<AuthState>()(
const newRefreshToken = tokens.refresh || responseData.refresh || data.refresh || null;
// CRITICAL: Set auth state AND immediately persist to localStorage
// This prevents race conditions where navigation happens before persist
set({
user: userData,
token: newToken,
@@ -250,10 +259,20 @@ export const useAuthStore = create<AuthState>()(
version: 0
};
localStorage.setItem('auth-storage', JSON.stringify(authState));
// CRITICAL: Also set tokens as separate items for API interceptor
// This ensures fetchAPI can access tokens immediately
if (newToken) {
localStorage.setItem('access_token', newToken);
}
if (newRefreshToken) {
localStorage.setItem('refresh_token', newRefreshToken);
}
} catch (e) {
console.warn('Failed to persist auth state to localStorage:', e);
}
// Return user data for success handling
return userData;
} catch (error: any) {
// ALWAYS reset loading on error - critical to prevent stuck state
@@ -261,7 +280,6 @@ export const useAuthStore = create<AuthState>()(
throw new Error(error.message || 'Registration failed');
} finally {
// Extra safety: ensure loading is ALWAYS false after register attempt completes
// This handles edge cases like network timeouts, browser crashes, etc.
const current = get();
if (current.loading) {
set({ loading: false });