question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

next auth middleware server error

See original GitHub issue

Description 🐜

getting Server error There is a problem with the server configuration. Check the server logs for more information.. there isn’t any console information.

import { withAuth } from 'next-auth/middleware';

export function middleware(req: any, ev: any) {
  console.log(process.env.NEXTAUTH_URL, process.env.NEXTAUTH_SECRET);
  return withAuth(req, {
    callbacks: {
      authorized: ({ token }) => !!token,
    },
  });
}

server logs

[next-auth][error][NO_SECRET]
https://next-auth.js.org/errors#no_secret
http://localhost:4200 my-super-secret-key
wait  - compiling /api/auth/[...nextauth]...
event - compiled client and server successfully in 106 ms (1570 modules)

Is this a bug in your own project?

Yes

How to reproduce ☕️

I’m using nx:13.7.2, nextjs 12.0.10, next-auth: 4.2.1. and the code above

Screenshots / Logs 📽

2022-02-04-072443_1920x1080_scrot

Environment 🖥

  System:
    OS: Linux 5.13 Manjaro Linux
    CPU: (16) x64 AMD Ryzen 7 3800X 8-Core Processor
    Memory: 7.54 GB / 15.58 GB
    Container: Yes
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.12.0 - ~/.nvm/versions/node/v16.12.0/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v16.12.0/bin/yarn
    npm: 8.1.0 - ~/.nvm/versions/node/v16.12.0/bin/npm
  Browsers:
    Firefox: 96.0.3
  npmPackages:
    next: 12.0.10 => 12.0.10
    next-auth: ^4.2.1 => 4.2.1
    react: 17.0.2 => 17.0.2

Contributing 🙌🏽

Yes, I am willing to help solve this bug in a PR

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
balazsorban44commented, Feb 4, 2022

That’s odd, the official example is deployed with it

https://github.com/nextauthjs/next-auth-example

You can see it in action on https://next-auth-example.vercel.app/me

I would need a reproduction. Could you please open a separate bug report with your attached code? I’ll do some digging myself.

1reaction
Fedeorlandaucommented, Feb 4, 2022

@balazsorban44 I’ve switched to the middleware you export and placed it into the folder (route group) I want to protect. It’s working pretty well so far. Thank you! Not sure what was wrong with my previous implementation, maybe my node_modules folder was acting funny, who knows.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Errors - NextAuth.js
Errors. This is a list of errors output from NextAuth.js. All errors indicate an unexpected problem, you should not expect to see errors....
Read more >
Error while setting up the middleware - withAuth / getToken
I have a problem with setting up the middleware for the next-auth. ... Server error There is a problem with the server configuration....
Read more >
Next auth middleware { default } is not working - Stack Overflow
Since Next.js 12.2, now you have to create a single middleware.ts file in your root directory (same level as pages folder).
Read more >
Advanced Features: Middleware - Next.js
Middleware allows you to run code before a request is completed, then based on the incoming request, you can modify the response by...
Read more >
there is a problem with the server configuration. nextauth
I used google as an auth provider with next auth. Configured all the the environment variables both in production and development. It's working...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found