fix(auth): resolve concurrent session token refresh and state syncing issues to prevent frequent logouts

This commit is contained in:
Christian Vidal Wolf
2026-05-26 12:49:22 +02:00
parent 070da5ad0f
commit 8ea63f60c8
4 changed files with 90 additions and 43 deletions
+7 -3
View File
@@ -182,13 +182,17 @@ export default function App() {
// Sync session state when localStorage is updated (e.g. by token refresh)
useEffect(() => {
const handleStorage = (e: StorageEvent) => {
if (e.key === 'craze_auth_session') {
const handleStorage = (e: Event) => {
if (e.type === 'session-refreshed' || (e as StorageEvent).key === 'craze_auth_session') {
setSession(getStoredSession());
}
};
window.addEventListener('storage', handleStorage);
return () => window.removeEventListener('storage', handleStorage);
window.addEventListener('session-refreshed', handleStorage);
return () => {
window.removeEventListener('storage', handleStorage);
window.removeEventListener('session-refreshed', handleStorage);
};
}, []);
useEffect(() => {