Supabase Auth Session Not Persisting Across Page Reloads
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.
Real developers can help you.
You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.
Get Help