enforce backend auth truth and prevent stale sessions#407
Conversation
|
@indresh404 is attempting to deploy a commit to the PRIYANSHU DOSHI's projects Team on Vercel. A member of the Team first needs to authorize it. |
Priyanshu-byte-coder
left a comment
There was a problem hiding this comment.
1. 401 → 404 regression — when !session.githubId the missing GitHub ID is an auth problem, not a missing resource. Keep 401. Returning 404 is semantically wrong and will confuse API consumers.
2. signOut() fires on network errors — AuthSessionValidator calls signOut() in the catch block unconditionally. A transient network timeout will log users out. Only call signOut() on HTTP 401/404 responses, not on fetch exceptions.
3. Duplicated GitHubApiError class — the same class and helper are copy-pasted identically into 4 route files. Extract into src/lib/github-error.ts and import.
Summary
Adds backend-backed auth session validation to prevent stale or mismatched authenticated states in the client.
This PR introduces a new
/api/auth/meendpoint to verify session-user mapping, adds startup auth validation with automatic sign-out for invalid sessions, improves GitHub account token lookup reliability, and adds reload buttons for better recovery UX.Closes #348
Type of Change
Changes Made
/api/auth/meendpoint to validate authenticated sessions against backend user records401/404responsesAuthSessionValidatorcomponent for startup auth verificationproviders.tsx.single()usage with.maybeSingle()in GitHub account token lookupPGRST116-style cascading failures from missing user rowsHow to Test
Steps for the reviewer to verify this works:
/api/auth/mereturns proper401or404responses for invalid states.single()errorsChecklist
npm run lintpasses locallynpm run type-check)