Skip to content

Fixed: Prevented authenticated users from re-accessing /auth route - #388

Open
syedbarkath980 wants to merge 1 commit into
AOSSIE-Org:mainfrom
syedbarkath980:fix-auth-route-redirect
Open

Fixed: Prevented authenticated users from re-accessing /auth route#388
syedbarkath980 wants to merge 1 commit into
AOSSIE-Org:mainfrom
syedbarkath980:fix-auth-route-redirect

Conversation

@syedbarkath980

@syedbarkath980 syedbarkath980 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

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

/auth was defined without any guard:

<Route path='/auth' element={<Authentication />} />

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 /auth route:

<Route
  path='/auth'
  element={
    isAuthenticated ? <Navigate to='/startDebate' replace /> : <Authentication />
  }
/>

This ensures authenticated users are always redirected away from auth pages.

Testing

  • Logged in via Google OAuth
  • Manually navigated to /auth

Before fix:

  • Login/signup page was shown again
unprotected-auth-route.mp4

After fix:

  • User is correctly redirected to /startDebate
after.unprotected-auth-route.mp4

Summary by CodeRabbit

  • Bug Fixes
    • Prevented authenticated users from accessing the authentication screen.
    • Authenticated users are now redirected directly to the debate start page.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The /auth route now redirects authenticated users to /startDebate and preserves the authentication page for unauthenticated users.

Changes

Authentication routing

Layer / File(s) Summary
Guard the authentication route
frontend/src/App.tsx
The /auth route conditionally renders Authentication or redirects authenticated users to /startDebate with history replacement.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: authenticated users are redirected away from /auth.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between bdcf739 and e493d3a.

📒 Files selected for processing (1)
  • frontend/src/App.tsx

Comment thread frontend/src/App.tsx
Comment on lines +62 to +64
<Route path='/auth'
element={ isAuthenticated ? <Navigate to='/startDebate' replace/> : <Authentication/> }
/>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant