auth-js icon indicating copy to clipboard operation
auth-js copied to clipboard

onAuthStateChange not triggered when using server-side signIn/signOut in Next.js with Supabase

Open bennajah opened this issue 7 months ago • 3 comments

Bug report

  • [x] I confirm this is a bug with Supabase, not with my own application.
  • [x] I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

When using the Supabase server client (from @supabase/ssr) to call signIn or signOut inside a Next.js server action, the auth state changes are not detected on the browser client (createBrowserClient()).

Specifically, onAuthStateChange() on the browser client does not fire when the sign-in or sign-out is done from a server action.

This leads to an inconsistent auth state in the frontend after using server-side auth methods.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Set up Supabase in a Next.js app using both createServerClient() and createBrowserClient()
  2. Set up onAuthStateChange() in a layout or component using the browser client.
  3. Trigger signIn() or signOut() using a server action via the server client.
  4. Notice that the browser does not detect any change in auth state.

Expected behavior

Calling signIn() or signOut() on the server should also update the browser-side auth state or trigger onAuthStateChange() accordingly, assuming the cookies are properly shared.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: [e.g. macOS, Windows]
  • Browser (if applies) [e.g. chrome, safari]
  • Version of supabase-js: [e.g. 6.0.2]
  • Version of Node.js: [e.g. 10.10.0]

Additional context

This behavior breaks real-time auth-dependent UI updates and makes sign-in/sign-out UX inconsistent.

bennajah avatar Jun 03 '25 15:06 bennajah