Is Next.js pages router supported? #383

Closed
opened 2026-03-13 07:44:02 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @PhillJK on GitHub (Dec 10, 2024).

Hi, I like the framework and want to use it my project. I have skimmed the docs, and found that all the examples are using new Next.js app router. I wanted to know if the pages router supported, or can be used (integrated) with the one, or there are some incompatibilities and restrictions?

Originally created by @PhillJK on GitHub (Dec 10, 2024). Hi, I like the framework and want to use it my project. I have skimmed the docs, and found that all the examples are using new Next.js app router. I wanted to know if the pages router supported, or can be used (integrated) with the one, or there are some incompatibilities and restrictions?
Author
Owner

@Bekacru commented on GitHub (Dec 12, 2024):

Since next page routers is express compatible, you can use the node adapter. So It should be supported!

@Bekacru commented on GitHub (Dec 12, 2024): Since next page routers is express compatible, you can use the node adapter. So It should be supported!
Author
Owner

@PhillJK commented on GitHub (Dec 12, 2024):

Since next page routers is express compatible, you can use the node adapter. So It should be supported!

Oh, I missed that the framework also supports node/express. Thank you, for your clarification and reply! I will look into it.

@PhillJK commented on GitHub (Dec 12, 2024): > Since next page routers is express compatible, you can use the node adapter. So It should be supported! Oh, I missed that the framework also supports node/express. Thank you, for your clarification and reply! I will look into it.
Author
Owner

@drshika commented on GitHub (Dec 20, 2024):

Hello! I think I might be missing something here. I ran into this issue:

Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/nanostores/index.js from .../node_modules/better-auth/dist/react.cjs not supported.

I tried adding in the Node Adapter as mentioned earlier to src/pages/api/auth/route.ts

import { NextApiRequest, NextApiResponse } from "next"
import { toNodeHandler } from "better-auth/node"
import { auth } from "@/lib/auth"

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
    await toNodeHandler(auth)(req, res)
}

however, this has not fixed the issue. would appreciate any pointers on how to fix this, thanks!

@drshika commented on GitHub (Dec 20, 2024): Hello! I think I might be missing something here. I ran into this issue: Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/nanostores/index.js from .../node_modules/better-auth/dist/react.cjs not supported. I tried adding in the Node Adapter as mentioned earlier to src/pages/api/auth/route.ts ```js import { NextApiRequest, NextApiResponse } from "next" import { toNodeHandler } from "better-auth/node" import { auth } from "@/lib/auth" export default async function handler(req: NextApiRequest, res: NextApiResponse) { await toNodeHandler(auth)(req, res) } ``` however, this has not fixed the issue. would appreciate any pointers on how to fix this, thanks!
Author
Owner

@PhillJK commented on GitHub (Dec 23, 2024):

Hello! I think I might be missing something here. I ran into this issue:

Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/nanostores/index.js from .../node_modules/better-auth/dist/react.cjs not supported.

I tried adding in the Node Adapter as mentioned earlier to src/pages/api/auth/route.ts

import { NextApiRequest, NextApiResponse } from "next"
import { toNodeHandler } from "better-auth/node"
import { auth } from "@/lib/auth"

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
    await toNodeHandler(auth)(req, res)
}

however, this has not fixed the issue. would appreciate any pointers on how to fix this, thanks!

Hi, I have not met this issue. Maybe something is wrong with your import/export settings.

Basically I have tried this

file path: /api/auth/[...all].js

import { toNodeHandler } from "better-auth/node";
import { auth } from "../../../utils/better-auth";

export const config = {
    api: {
        bodyParser: false,
    },
};

const authHandler = toNodeHandler(auth);

export default authHandler;

And it worked fine

@PhillJK commented on GitHub (Dec 23, 2024): > Hello! I think I might be missing something here. I ran into this issue: > > Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/nanostores/index.js from .../node_modules/better-auth/dist/react.cjs not supported. > > I tried adding in the Node Adapter as mentioned earlier to src/pages/api/auth/route.ts > > ```js > import { NextApiRequest, NextApiResponse } from "next" > import { toNodeHandler } from "better-auth/node" > import { auth } from "@/lib/auth" > > export default async function handler(req: NextApiRequest, res: NextApiResponse) { > await toNodeHandler(auth)(req, res) > } > ``` > > however, this has not fixed the issue. would appreciate any pointers on how to fix this, thanks! Hi, I have not met this issue. Maybe something is wrong with your import/export settings. Basically I have tried this file path: /api/auth/[...all].js ```js import { toNodeHandler } from "better-auth/node"; import { auth } from "../../../utils/better-auth"; export const config = { api: { bodyParser: false, }, }; const authHandler = toNodeHandler(auth); export default authHandler; ``` And it worked fine
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#383