Skip to Content

Common questions

Short answers about refresh tokens, expiry, storing tokens, caches, bundle size, and other ways to sign in.

These questions come up when you adopt Session kit. Each answer is short, and links to the page that covers the subject in full.

Do I need a refresh token?

No. Without a refresh token or a refresh callback, the user is signed out when the access token expires, or when authFetch gets a 401. See Authenticated requests for what happens after a 401, and Refresh to add a refresh later.

What if my backend doesn't say when the token expires?

The client still works. See Expiry for where the client looks for the expiry, and what it does when it finds none.

Is it safe to keep tokens in localStorage?

Any script on your origin can read them, as Security explains. If that isn't acceptable for your app, you have two options:

  • Keep the session on the server, in an httpOnly cookie, with server rendering.
  • Keep the tokens off disk with memoryStorage(). The session then ends when the page unloads. See Storage.

How do I use it with TanStack Query, or another cache?

Put state.sessionId in the query key, or clear the cache when it changes, so one account never reads another's data. With effetch-query, resetKey does it.

Why does TanStack Start in SPA mode flash my pending component?

The build prerenders an HTML shell, which the browser shows before any JavaScript runs. The client restores the session as soon as the script loads. Plain TanStack Router shows a blank page for the same moment. Give the shell a neutral pending component, as TanStack Start in SPA mode does.

What if some endpoints answer 401 for other reasons?

Turn off signOutOnRepeated401 in createAuthFetch's options. A second 401 from those endpoints then comes back to your code instead of signing the user out. Without a refresh token or a refresh callback, the first 401 still signs the user out. See Keep users signed in after a second 401.

How much does it add to my bundle?

About 11 kB gzipped for a single-page app with a router adapter and createAuthFetch. With server rendering, where the session work happens on the server, it's about 5 kB. The routers you don't use add nothing: see Entry points.

Yes, through your backend. Whatever your backend does to sign a user in, Session kit starts from the tokens it answers with. See What it doesn't do.

Next steps

  • Security: what Session kit protects, and what stays your backend's job.
  • Compatibility: the runtimes and versions Session kit supports.

On this page