Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware problem in Vercel, Next Auth V5, "message": "There was a problem with the server configuration. Check the server logs for more information." #11780

Closed
rodrigc opened this issue Sep 5, 2024 · 3 comments
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@rodrigc
Copy link

rodrigc commented Sep 5, 2024

Environment

  System:
    OS: macOS 14.6.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 3.45 GB / 32.00 GB
    Shell: 5.9 - /usr/local/bin/zsh
  Binaries:
    Node: 22.7.0 - /usr/local/bin/node
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 9.9.0 - /usr/local/bin/pnpm
  Browsers:
    Chrome: 128.0.6613.119
    Edge: 128.0.2739.63
    Safari: 17.6
  npmPackages:
    next: latest => 14.2.3
    next-auth: beta => 5.0.0-beta.17
    react: ^18 => 18.3.0

Reproduction URL

https://github.com/rodrigc/next-auth-v5

Describe the issue

I'm having the same problem reported by @ephraim888sun in #10137 and #10136.

I also mentioned the problem in jherr/next-auth-v5#1 , but I think that this might be a next-auth bug, so reporting here also.

I am testing it out now, and I am having a problem when trying to run in Vercel.

  1. I forked the repository: https://github.com/jherr/next-auth-v5 into https://github.com/rodrigc/next-auth-v5
  2. I added an .env file with AUTH_SECRET
  3. I added more debugging in the middleware: https://github.com/rodrigc/next-auth-v5/blob/main/src/middleware.ts#L9
  4. Everything works fine when testing locally on my laptop.
  5. When I deploy to Vercel, I see in my debugging that console.log(req.auth); shows:
Session: undefined
Auth object: {
  message: 'There was a problem with the server configuration. Check the server logs for more information.'
}

How to reproduce

  1. Deploy to vercel
vercel deploy --target=preview
  1. Access the URL of the application
  2. Look at the Vercel logs

Expected behavior

req.auth and req.auth.user should be correctly populated

@rodrigc rodrigc added bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Sep 5, 2024
@rodrigc
Copy link
Author

rodrigc commented Sep 6, 2024

I did some more debugging, and discovered that in a Vercel deployment,
the AUTH_SECRET variable was not being picked up from the .env file in my repository, and was not being set. This was the source of the problem.

@rodrigc
Copy link
Author

rodrigc commented Sep 6, 2024

In NextAuthRequest, auth is defined as either a Session or null,

auth: Session | null

but in this case where AUTH_SECRET is not set, I am seeing auth being set to:

{
  message: 'There was a problem with the server configuration. Check the server logs for more information.'
}

Is the fact that auth is being set to { message: string } a bug? Or should the type of NextAuthRequest be changed to:

export interface NextAuthRequest extends NextRequest {
  auth: Session | null | { message: string }
}

@balazsorban44
Copy link
Member

Reproduction is private/404s.

To answer your question, when deployed on Vercel, the preferred way to define variables is via the dashboard, not .env.

Can't tell more as there was no reproduction provided. Felel free to open a new issue with a public code repository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests

2 participants