Cookie not set in nextjs server action and ipAdress not being entered #256

Closed
opened 2026-03-13 07:39:57 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @myodan on GitHub (Nov 21, 2024).

Describe the bug
The documentation says that signing in with a server action sets a cookie, but... It doesn't set a cookie.

When you call a function that needs to set cookies, like signInEmail or signUpEmail in a server action, cookies won’t be set. This is because server actions need to use the cookies helper from Next.js to set cookies.

Now, when you call functions that set cookies, they will be automatically set.

To Reproduce
Follow the Get Started in the documentation. Set up the nextCookies() plugin. Run the code below in your server action.

"use server";
import { auth } from "@/lib/auth"
 
const signIn = async () => {
	await auth.api.signInEmail({
		body: {
			email: "user@email.com",
			password: "password",
		},
	});
};

Expected behavior
If the login is successful, the cookie should also be set.

Desktop (please complete the following information):

  • OS: Windows 11 23H2 (Build 22631.4460)
  • Browser: Chrome 131.0.6778.70
  • Version: 1.0.0-canary.8

Additional context
We're not sure if this is a bug or normal behavior, but the documentation and behavior are different, so we're creating an issue.

  • Additionally, if you pass in header, the userAgent is populated correctly, but the ipAdress is not.
  • The ipAdress is still not being entered even when using authClient.
Originally created by @myodan on GitHub (Nov 21, 2024). **Describe the bug** The [documentation](https://www.better-auth.com/docs/integrations/next#server-action-cookies) says that signing in with a server action sets a cookie, but... It doesn't set a cookie. > When you call a function that needs to set cookies, like **_signInEmail_** or **_signUpEmail_** in a server action, cookies won’t be set. This is because server actions need to use the cookies helper from Next.js to set cookies. > Now, when you call functions that set cookies, they will be **_automatically set_**. **To Reproduce** Follow the `Get Started` in the documentation. Set up the `nextCookies()` plugin. Run the code below in your server action. ```typescript "use server"; import { auth } from "@/lib/auth" const signIn = async () => { await auth.api.signInEmail({ body: { email: "user@email.com", password: "password", }, }); }; ``` **Expected behavior** If the login is successful, the cookie should also be set. **Desktop (please complete the following information):** - OS: Windows 11 23H2 (Build 22631.4460) - Browser: Chrome 131.0.6778.70 - Version: [1.0.0-canary.8](https://github.com/better-auth/better-auth/releases/tag/v1.0.0-canary.8) **Additional context** We're not sure if this is a bug or normal behavior, but the documentation and behavior are different, so we're creating an issue. - Additionally, if you pass in `header`, the `userAgent` is populated correctly, but the `ipAdress` is not. - The `ipAdress` is still not being entered even when using `authClient`.
Author
Owner

@Bekacru commented on GitHub (Nov 21, 2024):

this should be fixed on 1.0.0-canary.10. feel free to re-open if not.

@Bekacru commented on GitHub (Nov 21, 2024): this should be fixed on `1.0.0-canary.10`. feel free to re-open if not.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#256