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

next auth middleware server error #3802

Closed
always-maap opened this issue Feb 4, 2022 · 6 comments
Closed

next auth middleware server error #3802

always-maap opened this issue Feb 4, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@always-maap
Copy link

always-maap commented Feb 4, 2022

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

@always-maap always-maap added the bug Something isn't working label Feb 4, 2022
@balazsorban44
Copy link
Member

balazsorban44 commented Feb 4, 2022

Thanks for reporting. there has been a regression on vercel/next.js#33141 in Next.js.

For now, please use canary. The next latest release of Next.js should work soon again. 🙇

I also pushed a minor fix, please make sure you are on at least next-auth@4.2.1

@Fedeorlandau
Copy link

Thanks for reporting. there has been a regression on vercel/next.js#33141 in Next.js.

For now, please use canary. The next latest release of Next.js should work soon again. 🙇

I also pushed minor fix, please make sure you are on at least next-auth@4.2.1

Hi @balazsorban44, thank you for your response. Unfortunately, still happening to me.
System:

System:
    OS: macOS 12.0.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 12.72 GB / 32.00 GB
    Shell: 5.8 - /usr/local/bin/zsh
  Binaries:
    Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.0/bin/yarn
    npm: 8.1.0 - ~/.nvm/versions/node/v16.13.0/bin/npm
  Browsers:
    Chrome: 97.0.4692.99
    Safari: 15.1
  npmPackages:
    next: canary => 12.0.11-canary.4
    next-auth: ^4.2.1 => 4.2.1
    react: ^17.0.2 => 17.0.2

Error:

Unhandled Runtime Error
TypeError: result.response.headers is not iterable

Call Stack
DevServer.runMiddleware
/Users/user/Projects/web/node_modules/next/dist/server/next-server.js (786:58)

package.json

    "next": "canary",
    "next-auth": "^4.2.1",

Cheers,

@balazsorban44
Copy link
Member

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.

@always-maap
Copy link
Author

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.

next-auth@^4.2.1 and next@^12.0.11-canary.4 work perfectly for me. waiting for nextjs stable release to push to production. Thanks again. you are awesome

@balazsorban44
Copy link
Member

Unfortunately, I cannot find an issue, tested all the different initialization methods listed here: https://github.com/nextauthjs/next-auth/blob/main/packages/dev-app/pages/middleware-protected/_middleware.js

So all I can say is just make sure you are actually on 4.2.1 @Fedeorlandau. 🤔

@Fedeorlandau
Copy link

Fedeorlandau commented 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.

filiptronicek added a commit to interclip/next that referenced this issue Feb 12, 2022
We need to use this until Next v12.0.11, because of nextauthjs/next-auth#3802 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants