permissions: skip /permissions/available fetch on unauthenticated pages#1808
Conversation
UsersService is provided in root and eagerly creates an httpResource for /permissions/available, which auto-fires on app bootstrap before any auth check, leaking a 401 request from /login and other unauthenticated pages. Gate the request function on a new isAuthenticated signal in AuthService — seeded from the existing localStorage 'token_expiration' and flipped via setAuthenticated() at the login, session-restoration, and logout transitions already managed by AppComponent. Mirrors the connection-id gating used by the other httpResource-backed services. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughAdds an Angular Signal-based auth state to AuthService, updates AppComponent to call ChangesSignal-based Reactive Authentication
Sequence DiagramsequenceDiagram
participant AppComponent
participant AuthService
participant UsersService
participant PermissionsAPI
AppComponent->>AuthService: setAuthenticated(true) on login/session restore
AuthService->>UsersService: isAuthenticated signal update triggers
UsersService->>PermissionsAPI: fetch /permissions/available
PermissionsAPI-->>UsersService: permissions
AppComponent->>AuthService: setAuthenticated(false) on logout
UsersService->>UsersService: availablePermissions becomes undefined / cleared
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
frontend/src/app/app.component.ts (1)
353-361:⚠️ Potential issue | 🟠 Major | ⚡ Quick winClear local auth state even when
/user/logoutfails.Both logout paths only remove
token_expirationand flipisAuthenticatedinside the success callback. SinceAuthService.logOutUser()catches errors and returnsEMPTY(frontend/src/app/services/auth.service.ts, Lines 301-310), any failed logout request skips that callback and leaves the app authenticated locally.Move the local cleanup into a shared helper that runs before the request, or into a
finalize()path that always executes.Also applies to: 365-381
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@frontend/src/app/app.component.ts` around lines 353 - 361, The local auth cleanup (clearing token_expiration, setting isDemo and isAuthenticated, clearing currentUser) must run regardless of the HTTP logout result; modify logoutAndRedirectToRegistration (and the similar method around lines 365-381) to perform the local cleanup in a shared helper (e.g., applyLocalLogoutState()) or invoke it in an RxJS finalize() on the AuthService.logOutUser() observable so cleanup always executes even if logOutUser() returns EMPTY or errors; keep the navigation (router.navigate(['/registration']) or the other method’s redirect) in the success path if you want it conditional, but ensure the local state changes and localStorage.removeItem('token_expiration') are applied unconditionally via the helper/finalize.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@frontend/src/app/app.component.ts`:
- Around line 353-361: The local auth cleanup (clearing token_expiration,
setting isDemo and isAuthenticated, clearing currentUser) must run regardless of
the HTTP logout result; modify logoutAndRedirectToRegistration (and the similar
method around lines 365-381) to perform the local cleanup in a shared helper
(e.g., applyLocalLogoutState()) or invoke it in an RxJS finalize() on the
AuthService.logOutUser() observable so cleanup always executes even if
logOutUser() returns EMPTY or errors; keep the navigation
(router.navigate(['/registration']) or the other method’s redirect) in the
success path if you want it conditional, but ensure the local state changes and
localStorage.removeItem('token_expiration') are applied unconditionally via the
helper/finalize.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f6a2bf66-e4b3-4288-8c0d-6e4eaea5c192
📒 Files selected for processing (3)
frontend/src/app/app.component.tsfrontend/src/app/services/auth.service.tsfrontend/src/app/services/users.service.ts
….spec Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@frontend/src/app/app.component.spec.ts`:
- Around line 47-53: The isAuthenticatedSignal is shared across the suite
causing state leakage; modify the tests to recreate/reset the signal for each
test (e.g., move creation of isAuthenticatedSignal and mockAuthService into a
beforeEach or call isAuthenticatedSignal.set(false) in an afterEach) so each
test gets a fresh signal; update references to isAuthenticatedSignal,
mockAuthService, and its setAuthenticated wrapper accordingly to ensure
isolation between tests.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 40631277-d2a7-43ab-9647-f9d4875e4258
📒 Files selected for processing (1)
frontend/src/app/app.component.spec.ts
UsersService is provided in root and eagerly creates an httpResource for /permissions/available, which auto-fires on app bootstrap before any auth check, leaking a 401 request from /login and other unauthenticated pages. Gate the request function on a new isAuthenticated signal in AuthService — seeded from the existing localStorage 'token_expiration' and flipped via setAuthenticated() at the login, session-restoration, and logout transitions already managed by AppComponent. Mirrors the connection-id gating used by the other httpResource-backed services.
Summary by CodeRabbit
Bug Fixes
Behavior Change
Tests