TanStackT
TanStack2y ago
5 replies
radical-lime

Handle session expiry

Hi, is it correct to state that the authentication example cannot handle expired sessions?
From what I can tell, the _auth layout route is triggered when navigating to an auth route, but not when switching between auth routes.

Meaning that if a server session expires, these will not be detected, except if the authGuard is set for every authenticated route?

Basically what I want to achieve is, on accessing an auth route, getSessionFromLocalStorageIfLocalSessionTimeNotExpired(), if expired, try to get server session, if success consider authenticated, if failed unauthenticate. While doing getServerSession stay in a loading state.

I've tried for a while now, but it seems unachievable?

auth example:

https://stackblitz.com/edit/tanstack-router-jrjf5e?file=src%2Froutes%2F_auth.tsx&preset=node
StackBlitz
Run official live example code for Router Authenticated Routes, created by Tanstack on StackBlitz
Router Authenticated Routes Example (forked) - StackBlitz
Was this page helpful?