© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•7mo ago•
34 replies
Wilson Ibekason

Unexpected Supabase Auth Session Logout After 2–3 Seconds (email and OAuth)

I’m seeing a new issue in my React + Vite app where Supabase auth (email/password and OAuth) signs users in successfully but then automatically signs them out 2–3 seconds later—no error is shown.

Steps to Reproduce

1. User signs in (email/password or OAuth).
2. Supabase returns a valid session and access token.
3. After ~2–3 seconds, an
SIGNED_OUT
SIGNED_OUT
event fires and the session is cleared.

Expected
Users stay signed in until they explicitly sign out or the JWT expires.

Actual
The session is removed almost immediately after login.

---

Environment

*
@supabase/supabase-js
@supabase/supabase-js
 ^2.49.4
*
vite
vite
 ^5.4.1
* React + Vite
* Node.js (current LTS)
* Browsers: Chrome / Firefox / Edge

Auth Client Initialization

export const supabase = createClient<Database>(
  import.meta.env.VITE_SUPABASE_URL,
  import.meta.env.VITE_SUPABASE_ANON_KEY,
  {
    auth: {
      autoRefreshToken: true,
      persistSession: true,
      detectSessionInUrl: true,
    },
  }
);
export const supabase = createClient<Database>(
  import.meta.env.VITE_SUPABASE_URL,
  import.meta.env.VITE_SUPABASE_ANON_KEY,
  {
    auth: {
      autoRefreshToken: true,
      persistSession: true,
      detectSessionInUrl: true,
    },
  }
);


Key Hooks

useEffect(() => {
  // handle SIGNED_IN, TOKEN_REFRESHED, SIGNED_OUT, INITIAL_SESSION events
  const { data: { subscription }} = supabase.auth.onAuthStateChange(
    (event, sessionData) => { … }
  );
  // initial session fetch
  const { data: { session: initialSession }} = await supabase.auth.getSession();
  // setSession, setUser, setInitialized…
}, [queryClient, isFirstTimeUser, handleWelcomeEmail]);
useEffect(() => {
  // handle SIGNED_IN, TOKEN_REFRESHED, SIGNED_OUT, INITIAL_SESSION events
  const { data: { subscription }} = supabase.auth.onAuthStateChange(
    (event, sessionData) => { … }
  );
  // initial session fetch
  const { data: { session: initialSession }} = await supabase.auth.getSession();
  // setSession, setUser, setInitialized…
}, [queryClient, isFirstTimeUser, handleWelcomeEmail]);


---

What I’ve Tried

* Confirmed
persistSession: true
persistSession: true
.
* No errors in console/network.
* Env vars look correct.
* No stray sign-out logic elsewhere.

Questions

1. Are there known issues or config tweaks that could force immediate sign-outs?
2. Could cookie, CORS or SameSite policies be wiping the session?
3. Any extra logging or debug flags in
@supabase/supabase-js
@supabase/supabase-js
to trace why
SIGNED_OUT
SIGNED_OUT
is triggered?

Any pointers or debugging tips appreciated—thanks!
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Supabase logout should terminate oauth provider session
SupabaseSSupabase / help-and-questions
4w ago
supabase.auth.session() Error
SupabaseSSupabase / help-and-questions
4y ago
I cannot logout of supabase auth
SupabaseSSupabase / help-and-questions
13mo ago
SupaBase email AUTH using Brevo
SupabaseSSupabase / help-and-questions
5mo ago