Skip to content

fix(router): redirect authenticated users on root#18

Open
dev-kp-eloper wants to merge 1 commit into
avishek0769:mainfrom
dev-kp-eloper:fix/auth-redirect
Open

fix(router): redirect authenticated users on root#18
dev-kp-eloper wants to merge 1 commit into
avishek0769:mainfrom
dev-kp-eloper:fix/auth-redirect

Conversation

@dev-kp-eloper
Copy link
Copy Markdown

@dev-kp-eloper dev-kp-eloper commented May 20, 2026

Fix/Feature: Redirect Authenticated Users on Root (Closes #17)

Description

This PR resolves the suboptimal UX flow where users who are already logged in are served the static marketing landing page when navigating to the root URL (/). It wraps the root route in a PublicOnlyRoute guard, which automatically redirects signed-in users straight to the dashboard (/dashboard).

Root Cause

In src/App.tsx, the root route (path="/") was mapped directly to <LandingPage /> without any authentication guards. Because it bypassed the route guards entirely, already-logged-in users had to manually navigate to /dashboard or /chats.

Changes

  • src/App.tsx: Wrapped the root / path in the PublicOnlyRoute guard. This checks for active, unexpired JWT tokens in local storage synchronously prior to mounting LandingPage and performs an instant history replacement to /dashboard.

How to Verify

  • npm run dev → navigate to http://localhost:5173/ while unauthenticated to confirm the Landing Page still renders perfectly.
  • Simulate or complete a user login (storing a valid docchat_auth token in local storage).
  • Navigate to the root route http://localhost:5173/ again and confirm it immediately redirects to /dashboard client-side without flashing the landing page first.
  • Verify that clicking the browser back button does not redirect you again (clean history replacement).

Screenshots

Verified by client-side routing redirects.

@avishek0769
Copy link
Copy Markdown
Owner

Nice. Merging it after 1st June.

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.

Redirect authenticated users to Dashboard on root

2 participants