fix(router): redirect authenticated users on root#18
Open
dev-kp-eloper wants to merge 1 commit into
Open
Conversation
Owner
|
Nice. Merging it after 1st June. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 aPublicOnlyRouteguard, 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/dashboardor/chats.Changes
src/App.tsx: Wrapped the root/path in thePublicOnlyRouteguard. This checks for active, unexpired JWT tokens in local storage synchronously prior to mountingLandingPageand performs an instant history replacement to/dashboard.How to Verify
npm run dev→ navigate tohttp://localhost:5173/while unauthenticated to confirm the Landing Page still renders perfectly.docchat_authtoken in local storage).http://localhost:5173/again and confirm it immediately redirects to/dashboardclient-side without flashing the landing page first.Screenshots
Verified by client-side routing redirects.