next/headers import in an node/nestjs server, outside nextjs #1130

Closed
opened 2026-03-13 08:24:01 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @sebi75 on GitHub (Apr 29, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Create a nextjs app, add better-auth to login as in docs.
Add a separate server managed by nestjs and a sample route.
The sample route should do a simple session check, just like outlined here

Current vs. Expected behavior

Seems like better-auth tried to import nextjs header utils in a non nextjs environment.

Image

Expected behaviour is it doesn't as it shouldn't have access to such package.

What version of Better Auth are you using?

1.2.7

Provide environment information

- node:20-bullseye docker image

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

Backend

Additional context

No response

Originally created by @sebi75 on GitHub (Apr 29, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Create a nextjs app, add better-auth to login as in docs. Add a separate server managed by nestjs and a sample route. The sample route should do a simple session check, just like outlined [here](https://www.better-auth.com/docs/integrations/express) ### Current vs. Expected behavior Seems like better-auth tried to import nextjs header utils in a non nextjs environment. <img width="788" alt="Image" src="https://github.com/user-attachments/assets/6ff12059-6555-4a01-a0b4-19ffcb364d60" /> Expected behaviour is it doesn't as it shouldn't have access to such package. ### What version of Better Auth are you using? 1.2.7 ### Provide environment information ```bash - node:20-bullseye docker image ``` ### Which area(s) are affected? (Select all that apply) Backend ### Additional context _No response_
Author
Owner

@dosubot[bot] commented on GitHub (Jul 29, 2025):

Hi, @sebi75. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported that Better Auth v1.2.7 imports Next.js header utilities even when used in a non-Next.js environment like NestJS.
  • This causes issues during session checks in a NestJS route running alongside a Next.js app.
  • The package currently does not avoid Next.js dependencies outside of Next.js contexts.
  • No further comments or updates have been provided since the initial report.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of better-auth by commenting below.
  • If I do not hear back within 7 days, I will automatically close this issue.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Jul 29, 2025): Hi, @sebi75. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported that Better Auth v1.2.7 imports Next.js header utilities even when used in a non-Next.js environment like NestJS. - This causes issues during session checks in a NestJS route running alongside a Next.js app. - The package currently does not avoid Next.js dependencies outside of Next.js contexts. - No further comments or updates have been provided since the initial report. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of better-auth by commenting below. - If I do not hear back within 7 days, I will automatically close this issue. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1130