Clarify docs for API route creation for Next.js #2440

Closed
opened 2026-03-13 09:54:35 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @kai687 on GitHub (Dec 2, 2025).

It seems that one of the pages need to be updated. Since the example in the repo also uses auth, that's what I'm going to assume, but not sure.

  1. Check the following code from: 7. Mount handler:

    import { auth } from "@/lib/auth"; // path to your auth file
    import { toNextJsHandler } from "better-auth/next-js";
    
    export const { POST, GET } = toNextJsHandler(auth);
    
  2. Check the following code example from: Create API route:

    import { auth } from "@/lib/auth";
    import { toNextJsHandler } from "better-auth/next-js";
    
    export const { GET, POST } = toNextJsHandler(auth.handler);
    
Originally created by @kai687 on GitHub (Dec 2, 2025). It seems that one of the pages need to be updated. Since the example in the repo also uses `auth`, that's what I'm going to assume, but not sure. 1. Check the following code from: [7. Mount handler](https://www.better-auth.com/docs/installation#mount-handler): ```jsx import { auth } from "@/lib/auth"; // path to your auth file import { toNextJsHandler } from "better-auth/next-js"; export const { POST, GET } = toNextJsHandler(auth); ``` 1. Check the following code example from: [Create API route](https://www.better-auth.com/docs/integrations/next#create-api-route): ```jsx import { auth } from "@/lib/auth"; import { toNextJsHandler } from "better-auth/next-js"; export const { GET, POST } = toNextJsHandler(auth.handler); ```
GiteaMirror added the nextjsdocumentation labels 2026-03-13 09:54:35 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Dec 2, 2025):

It looks like there are two examples because the docs show two valid ways—depending on how you export your auth instance. If your auth file exports an auth instance (which already includes its handler internally), you can pass it directly to toNextJsHandler. In other words, use:

  export const { GET, POST } = toNextJsHandler(auth);

On the other hand, if your export only provides the handler function (for example when you’re doing some custom setup), then you’d call toNextJsHandler with auth.handler:

  export const { GET, POST } = toNextJsHandler(auth.handler);

You should choose the pattern that matches your auth export. If your auth file is similar to the repo example where auth is directly exported, then pass auth. Otherwise, if you only have the handler, pass auth.handler. Does that help clarify how to set up your Next.js API routes? Tag @better-auth-agent if you would like an answer from the Agent.

If you need more help, tag @Skyvern in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Dec 2, 2025): It looks like there are two examples because the docs show two valid ways—depending on how you export your auth instance. If your auth file exports an auth instance (which already includes its handler internally), you can pass it directly to toNextJsHandler. In other words, use:   export const { GET, POST } = toNextJsHandler(auth); On the other hand, if your export only provides the handler function (for example when you’re doing some custom setup), then you’d call toNextJsHandler with auth.handler:   export const { GET, POST } = toNextJsHandler(auth.handler); You should choose the pattern that matches your auth export. If your auth file is similar to the repo example where auth is directly exported, then pass auth. Otherwise, if you only have the handler, pass auth.handler. Does that help clarify how to set up your Next.js API routes? Tag @better-auth-agent if you would like an answer from the Agent. _If you need more help, tag @Skyvern in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2440