-
Notifications
You must be signed in to change notification settings - Fork 4
Fix access token not persisting on hard reload #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ibadia
merged 13 commits into
ibadia:main
from
MuhammadSadiqAli-EQ:add-login-signup-healthcheck-pages
Aug 18, 2026
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a3b9c72
Add login, signup, and backend health check pages with routing
MuhammadSadiqAli-EQ df634ba
Add login, signup, and health check pages with React Router patterns
MuhammadSadiqAli-EQ ca4ec45
Changes made according to agents.md
MuhammadSadiqAli-EQ 29ede31
Changes made according to agents.md
MuhammadSadiqAli-EQ 013920f
Refactor HealthCheckAPI response and remove docstring
MuhammadSadiqAli-EQ def72eb
Refactor authentication views for direct user handling
MuhammadSadiqAli-EQ 1168e0e
Revert backend changes
MuhammadSadiqAli-EQ 2fc3044
Revert backend changes
MuhammadSadiqAli-EQ 0cd82c7
Revert Backend Changes
MuhammadSadiqAli-EQ bcf0a2c
Fix hard reload logging out user, add protected route for auth check
Muhammad-Sadiq-Ali 8553038
Merge branch 'main' into add-login-signup-healthcheck-pages
MuhammadSadiqAli-EQ bdb339e
Added Expiry check on refreshAccesstoken before using it
Muhammad-Sadiq-Ali 077bafb
Fixed mismatching in backend and frontend lifetime of refresh Access …
Muhammad-Sadiq-Ali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,11 @@ | ||
| import { type RouteConfig, index, route } from "@react-router/dev/routes"; | ||
| import { type RouteConfig, layout, index, route } from "@react-router/dev/routes"; | ||
|
|
||
| export default [ | ||
| index("routes/home.tsx"), | ||
| route("login", "routes/login.tsx"), | ||
| route("signup", "routes/signup.tsx"), | ||
| layout("routes/protected-layout.tsx", [ | ||
| route("auth", "routes/authenticated.tsx"), | ||
| ]), | ||
| route("health", "routes/health.tsx"), | ||
| ] satisfies RouteConfig; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Temporary cuthentication checking tab | ||
|
|
||
| import type { Route } from "./+types/authenticated"; | ||
|
|
||
| export function meta({}: Route.MetaArgs) { | ||
| return [ | ||
| { title: "Authenticated" }, | ||
| { name: "description", content: "User is authenticated" }, | ||
| ]; | ||
| } | ||
|
|
||
| export default function AuthenticatedRoute() { | ||
| return <p>You are authenticated.</p>; | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // routes/protected-layout.tsx | ||
| import { Navigate, Outlet } from "react-router"; | ||
| import type { LoaderFunctionArgs } from "react-router"; | ||
| import { getAccessToken, getValidAccessToken } from "~/lib/auth"; | ||
|
|
||
| export async function clientLoader({ request }: LoaderFunctionArgs) { | ||
| const token = await getValidAccessToken(); | ||
| if (!token) { | ||
| throw new Response("Unauthorized", { status: 401 }); | ||
| } | ||
|
|
||
| return { token }; | ||
| } | ||
|
|
||
| export function ErrorBoundary() { | ||
| return <Navigate to="/login" replace />; | ||
| } | ||
|
|
||
| export default function ProtectedLayout() { | ||
| return <Outlet />; | ||
| } |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a valid access token means a token that is actually functioning, this function is only checking whether the token is present or no
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try checking if the token is actually valid through a quick backend call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a small function called isTokenExpired that decodes the JWT and compares the exp field to the current time. This gives us the same result as calling the backend would, but we skip the extra network call on every route load, so it's faster. Backend still does its own validation on real API calls, so nothing is less secure, we're just avoiding an unnecessary check upfront.