Fix auth redirect on landing page and inconsistent auth state#19
Merged
Conversation
Returning authenticated users hitting / were served the marketing landing page instead of being redirected to dashboard. Separately, get_current_user() only checked user_id in session without validating token expiry, causing /auth/status to report authenticated while upload endpoints returned 401 for sessions with expired tokens. Closes #18
|
🚅 Deployed to the BarcodeGenerator-pr-19 environment in LabelGenius
|
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.
Summary
/are now redirected to/dashboardinstead of seeing the marketing landing pageget_current_user()now validates token expiry and attempts a refresh before returning the user, making/auth/statusconsistent with whatverify_session_authenforces on upload/preview endpointsRoot causes
Bug 1: The
/route rendered<LandingPage />unconditionally — only/loginhad an auth check redirect. Returning users with a valid session saw the marketing page with the nav showing them as logged in, but had to navigate to dashboard manually.Bug 2:
get_current_user()(used by/auth/status) only checkeduser_idin session with no token validation.verify_session_auth(on/uploadand/preview) checked token expiry and tried to refresh. If a session's access token expired (15 min) and the refresh token was also expired (7 days), the nav and ProtectedRoute showed the user as authenticated while uploads returned 401. Observed via PostHog: users reaching the upload page with nolabel_generation_completedevents.Changes
backend/auth/decorators.py—get_current_user()now checksaccess_token_expires, callsrefresh_access_token()if expired, and returnsNoneif refresh failsfrontend-vite/react-ts/src/pages/LandingPage.tsx— added auth checkuseEffecton mount, redirects to/dashboardif authenticated, shows spinner while checking (mirrors existing pattern inlogin.tsx)Test plan
/— should redirect to/dashboard/— should show landing page normally/login, not let through and fail on uploadCloses #18