Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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 Error on Production (No Secret) #4411

Closed
batuhanbilginn opened this issue Apr 18, 2022 · 4 comments
Closed

Middleware Error on Production (No Secret) #4411

batuhanbilginn opened this issue Apr 18, 2022 · 4 comments
Labels
question Ask how to do something or how something works

Comments

@batuhanbilginn
Copy link

Environment

System:
OS: macOS 12.3
CPU: (10) x64 Apple M1 Pro
Memory: 24.96 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.14.0 - /usr/local/bin/node
npm: 8.3.1 - /usr/local/bin/npm
Browsers:
Chrome: 100.0.4896.88
Firefox: 97.0.1
Safari: 15.4
npmPackages:
next: latest => 12.0.8
next-auth: ^4.3.2 => 4.3.2
react: ^17.0.2 => 17.0.2

Reproduction URL


Describe the issue

I use this code block to detect if the user is authenticated or not. It works perfectly on local but it doesn't work on the production.

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

export default withAuth({
  callbacks: {
    authorized({ token }) {
      if (token) return true; // If there is a token, the user is authenticated
    },
  },
});

Screenshot 2022-04-18 at 13 33 30

Screenshot 2022-04-18 at 13 40 48

The error is "No Secret" but I already provided the NEXTAUTH_SECRET environment variable to the Vercel and I can verify that with successful login and cookie creation. Somehow, Middleware can't access the variable or there is something else.

How to reproduce

You can push your app with a middleware setup and try to use the code block that I provided or from the documentation.

Expected behavior

The code block should detect if the user is logged in or not.

@batuhanbilginn batuhanbilginn added the triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. label Apr 18, 2022
@promet99
Copy link

I have noticed this issue as well.
process.env.NEXTAUTH_SECRET in line 28 of next-auth/next/middleware.js does not exists.
Other env var were not available, and process.browser was true.
I believe this error is caused by middleware.js executed on the client side, not on the server side.

@promet99
Copy link

promet99 commented Apr 19, 2022

I also believe this issue to be related to #3878

@promet99
Copy link

And, this issue is caused by an error in next.js, which is fixed as of 12.1.4
I would recommend @batuhanbilginn to use latest version of next.js :)

@ThangHuuVu
Copy link
Member

Thanks, @promet99 for looking into it 🙏. Could you try upgrading next.js to the latest version and see if the error persists @batuhanbilginn?

@ThangHuuVu ThangHuuVu added question Ask how to do something or how something works and removed triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Apr 19, 2022
@nextauthjs nextauthjs locked and limited conversation to collaborators Apr 19, 2022
@ThangHuuVu ThangHuuVu converted this issue into discussion #4414 Apr 19, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question Ask how to do something or how something works
Projects
None yet
Development

No branches or pull requests

3 participants