#68 bug: auto logout

Closed
opened 5 months ago by fszontagh · 2 comments

If the session expired, refresh the page to fully logout the user. Currently after some time (i think supabase session expires) the user session deleted, but user can navigate on the page but just getting errors. This need to be fixed with a page refresh or a redirect to the landing page.

If the session expired, refresh the page to fully logout the user. Currently after some time (i think supabase session expires) the user session deleted, but user can navigate on the page but just getting errors. This need to be fixed with a page refresh or a redirect to the landing page.
claude commented 5 months ago
Collaborator

@fszontagh I'm starting work on this issue now!

I'll implement automatic logout/redirect when the Supabase session expires. My approach:

  1. Add a listener in AuthContext to detect session expiration
  2. When session expires, clear local state and redirect to landing page
  3. Ensure this works gracefully without throwing errors to the user

This will prevent users from navigating with an expired session and encountering errors.

@fszontagh I'm starting work on this issue now! I'll implement automatic logout/redirect when the Supabase session expires. My approach: 1. Add a listener in AuthContext to detect session expiration 2. When session expires, clear local state and redirect to landing page 3. Ensure this works gracefully without throwing errors to the user This will prevent users from navigating with an expired session and encountering errors.
claude commented 5 months ago
Collaborator

@fszontagh I've successfully fixed the auto logout issue! 🎉

Changes Made

I modified the AuthContext.tsx to handle session expiration gracefully:

1. Periodic Session Validation

  • Added a background session checker that runs every 5 minutes when the user is authenticated
  • Validates the session token with the backend to detect expiration early
  • Prevents users from navigating with an expired session

2. Full Page Refresh on Expiration

  • When session expires, the app now uses window.location.href = '/' instead of navigate()
  • This ensures a complete page refresh that resets all React state
  • Prevents the user from encountering errors while navigating with an expired session

3. Consistent Logout Behavior

  • All session expiration scenarios now trigger the same cleanup:
    • Remove session data from localStorage
    • Clear authentication state
    • Redirect to landing page with full refresh
  • Applied to all failure paths: invalid token, auth check failure, invalid session data

How It Works

  1. Background Monitoring: Every 5 minutes, the app checks if the session is still valid
  2. Immediate Detection: When session expires, it's detected either by the background check or on the next auth validation
  3. Clean Logout: All session data is cleared and the page refreshes to /, resetting the entire app state
  4. No More Errors: Users won't see errors or be able to navigate with an expired session

Testing Recommendations

To test this fix:

  1. Log in to the application
  2. Wait for the Supabase session to expire (or manually invalidate the token in localStorage)
  3. Try to navigate or wait for the background check to trigger
  4. The app should automatically refresh and redirect to the landing page

The changes have been committed and pushed to the repository (commit: fe70418).

@fszontagh I've successfully fixed the auto logout issue! 🎉 ## Changes Made I modified the `AuthContext.tsx` to handle session expiration gracefully: ### 1. **Periodic Session Validation** - Added a background session checker that runs every 5 minutes when the user is authenticated - Validates the session token with the backend to detect expiration early - Prevents users from navigating with an expired session ### 2. **Full Page Refresh on Expiration** - When session expires, the app now uses `window.location.href = '/'` instead of `navigate()` - This ensures a complete page refresh that resets all React state - Prevents the user from encountering errors while navigating with an expired session ### 3. **Consistent Logout Behavior** - All session expiration scenarios now trigger the same cleanup: - Remove session data from localStorage - Clear authentication state - Redirect to landing page with full refresh - Applied to all failure paths: invalid token, auth check failure, invalid session data ## How It Works 1. **Background Monitoring**: Every 5 minutes, the app checks if the session is still valid 2. **Immediate Detection**: When session expires, it's detected either by the background check or on the next auth validation 3. **Clean Logout**: All session data is cleared and the page refreshes to `/`, resetting the entire app state 4. **No More Errors**: Users won't see errors or be able to navigate with an expired session ## Testing Recommendations To test this fix: 1. Log in to the application 2. Wait for the Supabase session to expire (or manually invalidate the token in localStorage) 3. Try to navigate or wait for the background check to trigger 4. The app should automatically refresh and redirect to the landing page The changes have been committed and pushed to the repository (commit: `fe70418`).
Sign in to join this conversation.
No Milestone
No assignee
2 Participants
Loading...
Cancel
Save
There is no content yet.