Skip to content

fix(auth): add authentication guard and routing logic#66

Merged
steilerDev merged 2 commits into
betafrom
fix/auth-guard-routing
Feb 13, 2026
Merged

fix(auth): add authentication guard and routing logic#66
steilerDev merged 2 commits into
betafrom
fix/auth-guard-routing

Conversation

@steilerDev
Copy link
Copy Markdown
Owner

Summary

This PR implements the missing authentication guard that checks auth state on app load and redirects users appropriately. This fixes the issue where users on a fresh install were not presented with the setup screen.

Changes

  • AuthContext (client/src/contexts/AuthContext.tsx): Provides user, oidcEnabled, isLoading, error, and refreshAuth() to all components
  • AuthGuard (client/src/components/AuthGuard/AuthGuard.tsx): Guards protected routes by checking auth state and redirecting:
    • If setupRequired === true → redirect to /setup
    • If user === null (not authenticated) → redirect to /login
    • If user !== null (authenticated) → render protected routes
  • App.tsx: Wrap AppShell routes with AuthProvider and AuthGuard
  • SetupPage:
    • Check if setup is required on mount; redirect to /login if already complete
    • Redirect to /login after successful setup (instead of showing success message)
  • LoginPage:
    • Check if already authenticated on mount; redirect to home if so
    • Use navigate() for redirect after login instead of window.location.href
  • ProfilePage: Use AuthContext instead of separate getProfile() call
  • Loading state displayed while auth check is in progress

Testing

All quality gates pass:

  • npm run lint — 0 errors
  • npm run typecheck — all clean
  • npm run format:check — all clean
  • npm run build — success
  • npm audit — 0 vulnerabilities

Expected Behavior

  1. Fresh install (setupRequired): User is immediately redirected to /setup
  2. Setup complete, not logged in: User is redirected to /login
  3. Logged in: User can access all protected routes
  4. Accessing /setup when setup is complete: Redirects to /login
  5. Accessing /login when already authenticated: Redirects to home

Generated with Claude Code

Implement AuthGuard component to check authentication state on app load
and redirect users appropriately based on setup and authentication status.

Changes:
- Create AuthContext to provide user, oidcEnabled, and refreshAuth to the app
- Create AuthGuard component that checks auth state and redirects:
  - If setupRequired → redirect to /setup
  - If not authenticated → redirect to /login
  - If authenticated → render protected routes
- Wrap AppShell routes with AuthGuard in App.tsx
- Update SetupPage to check if setup is required on mount and redirect to
  /login if already complete
- Update SetupPage to redirect to /login after successful setup
- Update LoginPage to check if already authenticated and redirect to home
- Update LoginPage to use navigate() instead of window.location.href
- Update ProfilePage to use AuthContext instead of separate getProfile call
- Display loading state while auth check is in progress

Fixes the issue where users were not redirected to /setup on fresh install.

Co-Authored-By: Claude frontend-developer (Opus 4.6) <noreply@anthropic.com>
- Fix App.test.tsx to mock getAuthMe() and handle async auth loading
- Fix LoginPage.test.tsx to wrap component in AuthProvider
- Fix ProfilePage.test.tsx to mock useAuth() instead of getProfile()
- Add AuthGuard.test.tsx (7 tests: loading, redirects, auth states)
- Add AuthContext.test.tsx (7 tests: provider, refresh, error handling)

Co-Authored-By: Claude qa-integration-tester (Opus 4.6) <noreply@anthropic.com>
@steilerDev steilerDev merged commit 70bea22 into beta Feb 13, 2026
3 checks passed
@steilerDev steilerDev deleted the fix/auth-guard-routing branch February 13, 2026 13:39
@github-actions
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.7.0-beta.9 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.7.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants