fix: keep user state consistent after login and profile save#126
fix: keep user state consistent after login and profile save#126omsherikar merged 1 commit intomainfrom
Conversation
Merge partial API user payloads in updateUser. Hydrate session from /api/auth/me after login so GitHub and other fields match a full page load. Made-with: Cursor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Snapshot WarningsEnsure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice. Scanned FilesNone |
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis PR converts the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
👋 Thanks for opening this pull request! A maintainer will review it soon. Please make sure all CI checks pass. |
There was a problem hiding this comment.
Pull request overview
This PR aims to keep client-side auth/user state consistent after login and profile-related updates by ensuring the app hydrates a complete user object (matching what a full page load would produce).
Changes:
- Make
loginasync and hydrate the user fromGET /api/auth/meafter storing the access token. - Update login call sites (password login + OAuth callback) to
await login(...)so hydration completes before continuing UI flow. - Ensure
updateUsermerges user payloads (per PR intent) to prevent partial responses from overwriting existing user fields.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/hooks/useAuth.tsx | Makes login async and hydrates user state from /api/auth/me; updates auth context typing accordingly. |
| src/components/OAuthCallback.tsx | Awaits login after OAuth callback so auth state is hydrated before redirect flow continues. |
| src/components/LoginForm.tsx | Awaits login after password login to keep auth state consistent before subsequent navigation logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (result.success && result.data) { | ||
| // Update auth state | ||
| login(result.data.accessToken, result.data.user); | ||
| // Update auth state (hydrates from /api/auth/me for full user fields) | ||
| await login(result.data.accessToken, result.data.user); | ||
|
|
There was a problem hiding this comment.
handleOAuthCallback is typed to return data?: any (see src/utils/oauth.ts), so result.data can exist without accessToken and user. Calling login(result.data.accessToken, result.data.user) in that case can store the string "undefined" in localStorage and set an invalid auth state. Add explicit runtime validation for accessToken and user (and treat missing fields as an error) before calling login.
Merge partial API user payloads in updateUser. Hydrate session from /api/auth/me after login so GitHub and other fields match a full page load.
Summary by CodeRabbit
Release Notes