Bolt.new auth session keeps expiring — fix JWT refresh tokens
Bolt.new auth session keeps expiring — fix JWT refresh tokens
Bolt.new wires up Supabase Auth for sign-in and sign-up. It typically skips JWT refresh token handling, session persistence across page reloads, and the “remember me” functionality. Users get logged out after 1 hour (the JWT expiry default) or when they refresh the page. Three fixes cover 90% of session issues in Bolt apps.
Quick fix for Bolt.new auth session keeps expiring —
Fix 1 — Enable auto session refresh
When initialising the Supabase client, set autoRefreshToken: true:
createClient(url, key, {
auth: {
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: true,
},
});This tells the client to automatically refresh the JWT before it expires. If you already have this, check that you’re not creating multiple Supabase client instances — each one needs these settings.
Deeper fixes when the quick fix fails
- 02
Fix 2 — Restore session on page load
In your root layout or
_appequivalent, add:supabase.auth.getSession().then(({ data: { session } }) => { setSession(session); }); supabase.auth.onAuthStateChange((event, session) => { setSession(session); });The
onAuthStateChangehandler fires forSIGNED_IN,SIGNED_OUT,TOKEN_REFRESHED, andUSER_UPDATEDevents. - 03
Fix 3 — Verify localStorage persistence
Supabase’s client stores the session in localStorage by default. Check DevTools → Application → Local Storage for a
sb-*-auth-tokenkey.If it’s missing,
persistSessionis false somewhere. If it exists but the user is still logged out, check for code that callslocalStorage.clear()orsupabase.auth.signOut()unintentionally.
Still getting logged out?
Less common causes: (1) server-side rendering without session cookies configured — use @supabase/ssr package for Next.js, (2) cookie SameSite or Secure flags blocking persistence on HTTPS, (3) a service worker or CDN caching old auth responses.
Why AI-built apps hit Bolt.new auth session keeps expiring —
Supabase Auth uses JWTs with a default 1-hour expiry. The access token refreshes automatically — but only if your client-side code calls supabase.auth.getSession() on initialisation and handles the SIGNED_OUT event properly.
Bolt-generated apps often miss one or both steps. The sign-in screen works, the dashboard loads, and nobody notices until a real user refreshes the page or leaves the tab open for an hour.
“My users keep getting logged out every hour, is this expected?”
Diagnose Bolt.new auth session keeps expiring — by failure mode
Test your auth by signing in, then waiting 60 minutes without interacting. If you’re logged out, you need Fix #1. If refresh on any page logs you out, you need Fix #2.
| Symptom | Cause | Fix |
|---|---|---|
| Users logged out after exactly 1 hour | JWT expiry, no refresh token exchange | Fix #1 |
| Refresh page = logged out | Session not persisted in localStorage | Fix #2 |
| 'Remember me' checkbox does nothing | persistSession option not set | Fix #3 |
Related errors we fix
Still stuck with Bolt.new auth session keeps expiring —?
If any of these apply, a fixed-price auth fix will stabilise your users’ sessions in 48 hours:
- →Users report random logouts in Slack / support tickets
- →You're losing signups because returning users can't get back in
- →You've tried 'extending JWT expiry' and it didn't help
- →You need 'remember me' working before launch
Bolt.new auth session keeps expiring — questions
Why does my Bolt.new app log users out after 1 hour?+
Why does refreshing the page log users out of my Bolt.new app?+
How do I implement 'remember me' in Bolt.new + Supabase?+
Can I extend the Supabase JWT expiry past 1 hour?+
Why does onAuthStateChange fire multiple times in my Bolt.new app?+
How much does a Bolt.new auth fix cost?+
Ship the fix. Keep the fix.
Emergency Triage restores service in 48 hours. Break the Fix Loop rebuilds CI so this error cannot ship again.
Hyder Shah leads Afterbuild Labs, shipping production rescues for apps built in Lovable, Bolt.new, Cursor, Replit, v0, and Base44. our rescue methodology.
Bolt.new auth session keeps expiring — experts
If this problem keeps coming back, you probably need ongoing expertise in the underlying stack.