Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Better Auth · Function

nextCookies

nextCookies is a Better Auth plugin for Next.js server actions. It automatically applies authentication cookies emitted through Set-Cookie response headers.

How it works

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.

Syntax

nextCookies()

Key points

  • Use the plugin when Better Auth calls run in Next.js server actions and need to persist authentication cookies.
  • Cookie synchronization is triggered by a Set-Cookie response header.
  • After installation, cookie-setting Better Auth functions update the Next.js cookie store without extra cookie code.
  • Typical affected calls include email sign-in and email sign-up invoked from server actions.

Common mistakes

  • Place nextCookies() last in the Better Auth plugin array; the documentation explicitly requires that ordering.

Example: Enable nextCookies in Next.js

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.

When to use it

Server-action sign-in

A Next.js server action performs email authentication and must persist the resulting session cookie.

Server-action sign-up

A Next.js server action creates an account and needs the new authentication state stored in cookies.

Automatic response-cookie handling

An application wants response cookies from Better Auth API calls bridged into Next.js cookie handling without custom plumbing.

Interview questions

QWhat problem does nextCookies solve?

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.

QWhy is this needed in a server action?

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.

QHow do you configure it?

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.

  • signInEmail
  • signUpEmail
  • getSessionCookie
  • betterAuth

Source: Next. Js 13-15.1. X (edge.... Checked 2026-10-15.