API resolved without sending a response for /api/auth/get-session, this may result in stalled requests. #450

Closed
opened 2026-03-13 07:46:34 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @daveycodez on GitHub (Dec 21, 2024).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Integrate better-auth into a Next.js project with Pages Router and attempt to use get-session endpoint.

Get this message in console:

API resolved without sending a response for /api/auth/get-session, this may result in stalled requests.

Current vs. Expected behavior

Never let API resolve without getting the request

What version of Better Auth are you using?

1.0.22

Provide environment information

Next.js pages router

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

No response

Additional context

No response

Originally created by @daveycodez on GitHub (Dec 21, 2024). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Integrate better-auth into a Next.js project with Pages Router and attempt to use get-session endpoint. Get this message in console: ```shell API resolved without sending a response for /api/auth/get-session, this may result in stalled requests. ``` ### Current vs. Expected behavior Never let API resolve without getting the request ### What version of Better Auth are you using? 1.0.22 ### Provide environment information ```bash Next.js pages router ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) _No response_ ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 07:46:34 -05:00
Author
Owner

@daveycodez commented on GitHub (Dec 21, 2024):

Sorted it out.

The fix is to await the handler.

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

export const config = {
    api: {
        bodyParser: false, // Disallow body parsing, we will parse it manually
    },
}

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

You might want to update the docs to reflect this @Bekacru Also the docs are missing TypeScript types for the .ts example

EDIT

Way cleaner implementation:

/pages/api/auth/[...all].ts

import { toNodeHandler } from "better-auth/node"
import { auth } from "@/lib/auth"

// Disallow body parsing, we will parse it manually
export const config = { api: { bodyParser: false } }

export default toNodeHandler(auth.handler)
@daveycodez commented on GitHub (Dec 21, 2024): Sorted it out. The fix is to await the handler. ```ts import { NextApiRequest, NextApiResponse } from "next" import { toNodeHandler } from "better-auth/node" import { auth } from "@/lib/auth" export const config = { api: { bodyParser: false, // Disallow body parsing, we will parse it manually }, } export default async function handler(req: NextApiRequest, res: NextApiResponse) { await toNodeHandler(auth.handler)(req, res) } ``` You might want to update the docs to reflect this @Bekacru Also the docs are missing TypeScript types for the .ts example **EDIT** Way cleaner implementation: /pages/api/auth/[...all].ts ```ts import { toNodeHandler } from "better-auth/node" import { auth } from "@/lib/auth" // Disallow body parsing, we will parse it manually export const config = { api: { bodyParser: false } } export default toNodeHandler(auth.handler) ```
Author
Owner

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

thanks will update the docs!

@Bekacru commented on GitHub (Dec 21, 2024): thanks will update the docs!
Author
Owner

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

updated

@Bekacru commented on GitHub (Dec 23, 2024): updated
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#450