What is going on
After authenticating with Supabase, the user session disappears when the page is refreshed. Users are logged out unexpectedly, and the authentication state is not being maintained across browser sessions.
This typically happens because the auth session data is stored in memory only, rather than being persisted to localStorage or sessionStorage. When the page reloads, the in-memory state is lost.
Common causes
- Missing localStorage persistence in Supabase client initialization
- Incorrect session storage configuration in createClient()
- localStorage disabled in browser or private browsing mode
- Auth state listener not properly initialized before component mount
- Session token expired without refresh token handling
How to fix it
Initialize Supabase client with proper storage configuration:
const supabase = createClient(URL, KEY, {
auth: {
storage: localStorage,
autoRefreshToken: true,
persistSession: true
}
})Add auth state listener on app mount to restore session from localStorage.
Getting help takes about a minute
No hiring, no back and forth. A real person looks at your app.
-
1
Describe it
Tell us what you need in plain words. You don't have to be technical or have an account to start.
-
2
Free 15-minute call
A verified developer calls you. Many tasks are sorted right there, and it costs nothing.
-
3
Pay after you approve
If there is more to do, you get one fixed price up front. You pay only once you are happy.
Real people, reviewed by hand
Developers who do this every day
Every developer is approved by our team before they can take a task. Describe yours and the first one who is free picks it up.
Get helpQuestions
Why is my user logged out after refresh?
Check if persistSession is enabled and localStorage is available. Add an auth state listener on app mount to restore the session.
How do I check if session is stored?
Open DevTools > Application > Local Storage and look for 'sb-' prefixed keys containing auth tokens.