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.
I'll implement automatic logout/redirect when the Supabase session expires. My approach:
Add a listener in AuthContext to detect session expiration
When session expires, clear local state and redirect to landing page
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.
@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
Background Monitoring: Every 5 minutes, the app checks if the session is still valid
Immediate Detection: When session expires, it's detected either by the background check or on the next auth validation
Clean Logout: All session data is cleared and the page refreshes to /, resetting the entire app state
No More Errors: Users won't see errors or be able to navigate with an expired session
Testing Recommendations
To test this fix:
Log in to the application
Wait for the Supabase session to expire (or manually invalidate the token in localStorage)
Try to navigate or wait for the background check to trigger
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`).
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.
@fszontagh I'm starting work on this issue now!
I'll implement automatic logout/redirect when the Supabase session expires. My approach:
This will prevent users from navigating with an expired session and encountering errors.
@fszontagh I've successfully fixed the auto logout issue! 🎉
Changes Made
I modified the
AuthContext.tsxto handle session expiration gracefully:1. Periodic Session Validation
2. Full Page Refresh on Expiration
window.location.href = '/'instead ofnavigate()3. Consistent Logout Behavior
How It Works
/, resetting the entire app stateTesting Recommendations
To test this fix:
The changes have been committed and pushed to the repository (commit:
fe70418).