Server-action sign-in
A Next.js server action performs email authentication and must persist the resulting session cookie.
Better Auth · Function
nextCookies is a Better Auth plugin for Next.js server actions. It automatically applies authentication cookies emitted through Set-Cookie response headers.
The nextCookies plugin integrates Better Auth with Next.js server actions. It watches authentication responses and uses Next.js cookie handling to apply any Set-Cookie headers automatically, allowing operations such as email sign-in or sign-up to establish cookies without manually calling the Next.js cookies helper.
nextCookies()Set-Cookie response header.nextCookies() last in the Better Auth plugin array; the documentation explicitly requires that ordering.import { betterAuth } from "better-auth";
import { nextCookies } from "better-auth/next-js";
export const auth = betterAuth({
plugins: [nextCookies()],
});Register the plugin last in the Better Auth plugin list so server actions can apply cookies emitted by authentication responses.
A Next.js server action performs email authentication and must persist the resulting session cookie.
A Next.js server action creates an account and needs the new authentication state stored in cookies.
An application wants response cookies from Better Auth API calls bridged into Next.js cookie handling without custom plumbing.
It is a Next.js integration plugin for Better Auth server actions. It automatically applies cookies whenever an authentication response includes a Set-Cookie header.
Follow-up: Why is plugin order relevant? The documented configuration requires this plugin to be last, so later plugins do not interfere with its response-cookie handling.
Next.js server actions do not automatically set cookies from Better Auth responses because cookie mutation must use Next.js's cookies helper. The plugin handles that integration automatically.
Follow-up: Which operations benefit? Server-side operations that need to establish or update authentication cookies, such as email sign-in and sign-up.
Import nextCookies from better-auth/next-js, call it in the plugins array, and put it at the end of that array. After that, cookie-setting authentication calls can update cookies automatically.
Follow-up: What should remain separate? Middleware or proxy session checks should not be treated as full session validation; protected actions still require server-side validation.
signInEmailsignUpEmailgetSessionCookiebetterAuth