Fixed: Prevented authenticated users from re-accessing /auth route - #388
Fixed: Prevented authenticated users from re-accessing /auth route#388syedbarkath980 wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughThe ChangesAuthentication routing
Estimated code review effort: 1 (Trivial) | ~2 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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.
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.tsx`:
- Around line 62-64: Update the /auth route element to use AuthProvider’s
token-verification loading state before rendering Authentication: keep the
pending state visible while verifyToken() settles, then navigate authenticated
users to /startDebate and show Authentication only for unauthenticated users.
Locate the relevant loading state and verification flow in AuthProvider and
apply the gate in the Route definition.
🪄 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 Plus
Run ID: 2ec491fa-4646-4935-99f1-ec0dec37c2fd
📒 Files selected for processing (1)
frontend/src/App.tsx
| <Route path='/auth' | ||
| element={ isAuthenticated ? <Navigate to='/startDebate' replace/> : <Authentication/> } | ||
| /> |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== files =="
git ls-files | grep -E '(^|/)frontend/src/App\.tsx$|AuthProvider|AuthContext|Route|Authentication' | sed -n '1,120p'
echo "== App.tsx outline/sections =="
wc -l frontend/src/App.tsx
sed -n '1,130p' frontend/src/App.tsx
echo "== auth symbols =="
rg -n "AuthProvider|authContext|isAuthenticated|loading|Authentication|ProtectedRoute|startDebate|auth" frontend/src -S | sed -n '1,240p'Repository: AOSSIE-Org/DebateAI
Length of output: 23230
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== authContext.tsx first 220 lines =="
sed -n '1,220p' frontend/src/context/authContext.tsx | cat -n
echo "== authContext.tsx later relevant lines =="
sed -n '220,370p' frontend/src/context/authContext.tsx | cat -n
echo "== package deps for React/Router =="
if [ -f frontend/package.json ]; then sed -n '1,140p' frontend/package.json; fi
echo "== local react-router-dom version lock if present =="
fd -a 'package-lock.json|pnpm-lock.yaml|yarn.lock|bun.lockb' frontend . | sed -n '1,40p'Repository: AOSSIE-Org/DebateAI
Length of output: 17354
Show a loading state while restoring the auth token.
AuthProvider reads token from localStorage first, so on app start any valid token renders as isAuthenticated === true before verifyToken() settles. If a user lands on /auth and has a stored token, they get the login UI briefly instead of staying in auth-pending and then navigating to /startDebate. Set loading during token verification and gate /auth on that state before showing Authentication.
🤖 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.tsx` around lines 62 - 64, Update the /auth route element to
use AuthProvider’s token-verification loading state before rendering
Authentication: keep the pending state visible while verifyToken() settles, then
navigate authenticated users to /startDebate and show Authentication only for
unauthenticated users. Locate the relevant loading state and verification flow
in AuthProvider and apply the gate in the Route definition.
Bug
When a user is already authenticated and manually navigates to
/auth(e.g. via the URL bar), the app shows the login/signup page instead of redirecting them back into the app. This creates confusing UX, as it looks like the user has been logged out even though their session is still valid.Root Cause
/authwas defined without any guard:Allowing authenticated users to access the authentication page,
Leading to confusion, unnecessary API Calls and can also occur tiny issues/bugs in future.
Fix
Added the logic to the
/authroute:This ensures authenticated users are always redirected away from auth pages.
Testing
/authBefore fix:
unprotected-auth-route.mp4
After fix:
/startDebateafter.unprotected-auth-route.mp4
Summary by CodeRabbit