[GH-ISSUE #1054] nextCookies plugin not updating header with signUpEmail in nextjs server action #8568

Closed
opened 2026-04-13 03:41:15 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @Robstei on GitHub (Dec 28, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1054

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

reproduction: https://github.com/Robstei/better-auth-signinemail-next-no-refresh

  1. run docker compose up
  2. click login. It will work but you have to refresh for the navbar to update.
  3. click logout. It will work and the navbar will update.

Current vs. Expected behavior

I would expect the page to rerender with the menu item that is only for users.
Next invalidates the router cache when cookies are manipulated and that is what the nextCookies plugin does.

I have included logging that shows that the navbar rerenders on login but does not get updated header values during render.
The cookies are updated tho. The headers do not include the new cookie value.
Maybe cookies are not properly set in the header on auth.api.signInEmail

What version of Better Auth are you using?

1.1.4

Provide environment information

- OS: Ubuntu 24.4
- Browser: Chrome

Which area(s) are affected? (Select all that apply)

Backend, Package, Other

Auth config (if applicable)

export const auth = betterAuth({
  plugins: [nextCookies()],
  emailAndPassword: {
    enabled: true,
  },
  database: drizzleAdapter(db, {
    provider: "pg",
  }),
});

Additional context

I have asked about it here: https://discord.com/channels/1288403910284935179/1322311610731335730

Originally created by @Robstei on GitHub (Dec 28, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1054 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce reproduction: https://github.com/Robstei/better-auth-signinemail-next-no-refresh 1. run docker compose up 2. click login. It will work but you have to refresh for the navbar to update. 3. click logout. It will work and the navbar will update. ### Current vs. Expected behavior I would expect the page to rerender with the menu item that is only for users. Next invalidates the router cache when cookies are manipulated and that is what the nextCookies plugin does. I have included logging that shows that the navbar rerenders on login but does not get updated header values during render. The cookies are updated tho. The headers do not include the new cookie value. Maybe cookies are not properly set in the header on `auth.api.signInEmail` ### What version of Better Auth are you using? 1.1.4 ### Provide environment information ```bash - OS: Ubuntu 24.4 - Browser: Chrome ``` ### Which area(s) are affected? (Select all that apply) Backend, Package, Other ### Auth config (if applicable) ```typescript export const auth = betterAuth({ plugins: [nextCookies()], emailAndPassword: { enabled: true, }, database: drizzleAdapter(db, { provider: "pg", }), }); ``` ### Additional context I have asked about it here: https://discord.com/channels/1288403910284935179/1322311610731335730
GiteaMirror added the lockedbug labels 2026-04-13 03:41:15 -05:00
Author
Owner

@sagargupta commented on GitHub (Feb 1, 2025):

Any update on this issue? This is common problem and there's no way to get session on the server side.

<!-- gh-comment-id:2628769195 --> @sagargupta commented on GitHub (Feb 1, 2025): Any update on this issue? This is common problem and there's no way to get session on the server side.
Author
Owner

@f8al3rr commented on GitHub (Feb 16, 2025):

Any updates on this? Really frustrating, makes simple processes in Nextjs a huge headache..

<!-- gh-comment-id:2661197289 --> @f8al3rr commented on GitHub (Feb 16, 2025): Any updates on this? Really frustrating, makes simple processes in Nextjs a huge headache..
Author
Owner

@dosubot[bot] commented on GitHub (Jun 14, 2025):

Hi, @Robstei. I'm Dosu, and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • Reported issue with nextCookies plugin in Better Auth version 1.1.4.
  • Header does not update with signUpEmail in Next.js server action, requiring manual refresh.
  • Cookies update correctly, but header remains unchanged.
  • Users sagargupta and f8al3rr have expressed frustration and are seeking updates.
  • Ongoing discussion on Discord for additional insights.

Next Steps:

  • Please confirm if this issue is still relevant to the latest version of the better-auth repository by commenting here.
  • If no updates are provided, the issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

<!-- gh-comment-id:2972847699 --> @dosubot[bot] commented on GitHub (Jun 14, 2025): Hi, @Robstei. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale. **Issue Summary:** - Reported issue with nextCookies plugin in Better Auth version 1.1.4. - Header does not update with signUpEmail in Next.js server action, requiring manual refresh. - Cookies update correctly, but header remains unchanged. - Users sagargupta and f8al3rr have expressed frustration and are seeking updates. - Ongoing discussion on Discord for additional insights. **Next Steps:** - Please confirm if this issue is still relevant to the latest version of the better-auth repository by commenting here. - If no updates are provided, the issue will be automatically closed in 7 days. Thank you for your understanding and contribution!
Author
Owner

@ping-maxwell commented on GitHub (Aug 8, 2025):

I assume you're using useSession?
Usually when you update the user on the server, useSession wouldn't know that and thus won't fetch the new session details.
After calling your server action you should call refetch provided from useSession to make it fetch new session data.

<!-- gh-comment-id:3166232114 --> @ping-maxwell commented on GitHub (Aug 8, 2025): I assume you're using useSession? Usually when you update the user on the server, useSession wouldn't know that and thus won't fetch the new session details. After calling your server action you should call `refetch` provided from `useSession` to make it fetch new session data.
Author
Owner

@ping-maxwell commented on GitHub (Aug 11, 2025):

I'm closing this due to inactivity, please send a message if still interested and I can reopen it.

<!-- gh-comment-id:3175569761 --> @ping-maxwell commented on GitHub (Aug 11, 2025): I'm closing this due to inactivity, please send a message if still interested and I can reopen it.
Author
Owner

@bennettdams commented on GitHub (Aug 11, 2025):

@ping-maxwell Not OP, but maybe this helps: I'm not sure if this should be considered a bug or if this a missing feature.

Some background:

Show new session data on the server and/or client after session update (sign in, change username, ...) and vice versa
https://github.com/better-auth/better-auth/discussions/2898

Support initial data in React useSession hook for SSR scenarios
https://github.com/better-auth/better-auth/issues/2768

<!-- gh-comment-id:3176213329 --> @bennettdams commented on GitHub (Aug 11, 2025): @ping-maxwell Not OP, but maybe this helps: I'm not sure if this should be considered a bug or if this a missing feature. Some background: Show new session data on the server and/or client after session update (sign in, change username, ...) and vice versa https://github.com/better-auth/better-auth/discussions/2898 Support initial data in React useSession hook for SSR scenarios https://github.com/better-auth/better-auth/issues/2768
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8568