fix(signup): refetch session data on signup#1155
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR addresses a session management bug in the user signup flow where stale session data from previously logged-out accounts was causing permission issues during email verification. The core problem occurred because when users logged out of one account and immediately signed up for a new account, the verification hook (use-verification.ts) would use cached session data from the old account, leading to invalid permissions.
The fix implements two complementary changes:
-
Session Refetching in Signup Form: After successful user registration, the signup form now explicitly calls
refetchSession()from theuseSessionhook to immediately fetch the new user's session data. This ensures the session store contains fresh, accurate data for the newly created account rather than relying on potentially stale cached data. -
Navigation Method Change in Verification Flow: The verification hook switches from Next.js router navigation (
router.push()) to browser-native navigation (window.location.href) for redirects. This change forces a full page reload, which helps clear any remaining cached state and ensures the new session is properly loaded throughout the application.
Additionally, the redirect delay is reduced from 2000ms to 1000ms to improve user experience. The session refetch operation includes proper error handling that allows the verification flow to continue gracefully even if the session refresh fails, since the verification process has its own mechanisms to handle session issues.
These changes work together to ensure that the verification flow always operates with the correct user session data, preventing permission errors that could occur when users rapidly switch between accounts.
Confidence score: 4/5
- This PR addresses a specific session management bug with a targeted solution that should resolve the permission issues without breaking existing functionality
- Score reflects well-structured error handling and logical approach to session state management, though the navigation method change adds some complexity
- Pay close attention to the navigation changes in
use-verification.tsas switching from router to window.location could affect other parts of the application that expect router-based navigation
2 files reviewed, no comments
9481619 to
80441ba
Compare
Summary
refetch session data on signup, since old session if just logged out of another acct was being used in the use-verify hook, and yielded invalid permissions. now, we refetch session data on signup to force grab the new user session instead.
Type of Change
Testing
Tested manually.
Checklist