Im using the better-auth in a non-nextjs server to verify session and see this error.

error Cannot find module '/app/node_modules/next/headers' imported from /app/node_modules/better-auth/dist/integrations/next-js.cjs Did you mean to import "next/headers.js"?
4 Replies
Sebastian
SebastianOP5mo ago
how can I fix this? Seems like better-auth it's trying to import next/headers in a non next-js environment. This should not happen
DeepSeek R2
DeepSeek R25mo ago
just pass headers to it. for example this hono's header:
const session = await auth(db, c.env).api.getSession({
headers: c.req.raw.headers,
});
const session = await auth(db, c.env).api.getSession({
headers: c.req.raw.headers,
});
Sebastian
SebastianOP5mo ago
Im passing headers
const session = await this.authService.getAuth().api.getSession({
headers: this.authService.getFromNodeHeaders()(req.headers),
});
const session = await this.authService.getAuth().api.getSession({
headers: this.authService.getFromNodeHeaders()(req.headers),
});
ElonMask
ElonMask4mo ago
any luck with this? im on t3 stack w pages router, trynna integrate better-auth.

Did you find this page helpful?