Commit 63ad762
fix: wait for auth initialization in guards to prevent race condition
This fixes the race condition where guards check authentication before
AuthService finishes loading the session, causing false redirects to
login even when users are authenticated.
Problem:
- AuthService.initializeAuth() is async and called in constructor
- Guards were checking isAuthenticated() immediately
- If auth still loading, user is null → guard redirects to login
- This caused all E2E tests to fail with timeouts and missing elements
Solution:
- Added waitForAuthReady() method in AuthService that waits for
loading state to complete
- Updated authGuard to await auth initialization before checking
- Updated adminGuard to await auth initialization before checking
- Uses efficient polling with 50ms intervals
This ensures:
1. Guards always check auth status AFTER session is loaded
2. No false redirects to login for authenticated users
3. E2E tests can properly navigate protected routes
4. Admin panel routes accessible to admin users
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 168bac1 commit 63ad762
3 files changed
Lines changed: 28 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
115 | 136 | | |
116 | 137 | | |
117 | 138 | | |
| |||
0 commit comments