Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lib/stores/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export const useAuthStore = create((set, get) => ({
}
return { error: 'Session expired' };
} catch {
localStorage.removeItem('qrypt_session');
localStorage.removeItem('supabase.auth.token');
return { error: 'Failed to get session' };
}
},
Expand Down
13 changes: 13 additions & 0 deletions tests/stores/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ describe('Auth Store (Zustand)', () => {
expect(result.success).toBe(false);
});

it('clears corrupted stored session data', async () => {
window.localStorage.getItem.mockImplementation((key) => {
if (key === 'qrypt_session') return 'not-json';
return null;
});

const result = await useAuthStore.getState().getCurrentSession();

expect(result.error).toBe('Failed to get session');
expect(window.localStorage.removeItem).toHaveBeenCalledWith('qrypt_session');
expect(window.localStorage.removeItem).toHaveBeenCalledWith('supabase.auth.token');
});

it('logs out and clears user state', async () => {
useAuthStore.setState({ user: { id: '123', username: 'test' } });
await useAuthStore.getState().logout();
Expand Down
Loading