Skip to content

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

@bennajah

Description

@bennajah

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    auth-jsRelated to the auth-js library.bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions