fix(auth): resolve reactivity bug and improve error handling

- Fix Vue reactivity bug in isAuthenticated computed property by
  reordering condition to ensure dependency tracking (!!user.value
  before pb.authStore.isValid)
- Fix cross-tab sync onChange listener to handle logout by using
  nullish coalescing for undefined model
- Add user-friendly error message mapping in login catch block
- Export initAuth method from useAuth composable
- Add auth.client.ts plugin for client-side auth initialization
- Remove debug console.log statements that masked the Heisenbug
- Simplify auth.client plugin tests to structural checks due to
  Nuxt's test environment auto-importing defineNuxtPlugin
- Update test expectations for new error message behaviour
This commit is contained in:
2026-01-28 16:18:20 +01:00
parent 64d9df5469
commit fe2bc5fc87
7 changed files with 49 additions and 718 deletions

View File

@@ -234,8 +234,8 @@ describe('useAuth', () => {
await auth.login('github'); // Not in mockProviders
expect(auth.error.value).toBeDefined();
expect(auth.error.value?.message).toContain('github');
expect(auth.error.value?.message).toContain('not configured');
// User-friendly error message is shown instead of raw error
expect(auth.error.value?.message).toBe('This login provider is not available. Contact admin.');
});
it('should handle OAuth errors gracefully', async () => {
@@ -247,7 +247,9 @@ describe('useAuth', () => {
await auth.login('google');
expect(auth.error.value).toEqual(mockError);
// User-friendly error message is shown instead of raw error
expect(auth.error.value).toBeDefined();
expect(auth.error.value?.message).toBe('Login failed. Please try again later.');
expect(auth.loading.value).toBe(false);
});
@@ -278,7 +280,8 @@ describe('useAuth', () => {
await auth.login('google');
expect(auth.error.value).toBeDefined();
expect(auth.error.value?.message).toContain('not configured');
// User-friendly error message is shown instead of raw error
expect(auth.error.value?.message).toBe('This login provider is not available. Contact admin.');
});
});