[SOLVED] Help! VERCEL - ERROR NEXTJS Authentication on prod. Error: 401 Unauthorized

Hi, here is the logs when I call the function

Errors are empty

There are Error 304 on “[GET] /api/auth/providers” and on “[GET] /api/auth/csrf”, then Error 401 on “[POST] /api/auth/callback/moralis-auth”

Were you able test the production build on localhost environment without any errors?

If yes, then can you share your production url? I will try to test it on my end.

I tried build on localhost environment. I have no error while building. But I have the same error locally. On localhost dev it works fine.

Here is the url to try : https://test-auth-g5h5f2n00-kroustof.vercel.app/signin

I see this error in console when i click on the login button. It did not open metamask

If you test this Moralis repo (https://github.com/MoralisWeb3/demo-apps/tree/main/nextjs_moralis_auth.) in production, do you have any issue to make it works ?

My repo is basically a copy paste of the authentication tutorial with NEXT JS, so I don’t know what to do…

It prompts normally when I click on login… I will try again

try this link: test-auth-flax.vercel.app

I deployed something long back. But not sure if your code is similar to mine.
https://moralisauth.vercel.app/signin

New Url gave me this error in console. Is it the same error which you are seeing?

Yours works fine. But Moralis has recently updated their API and packge ‘@moralisweb3/next’ with a new tutorial… It seems the problem may come from that

Yes, this is the same error

hmm, let me try deploying the latest version and I will get back to you.

If you have time, may I ask you to try to deploy the tutorial repo and see if it works to know if I am doing something wrong on my part

1 Like

Here is the latest build. I copied the code directly from tutorial repo and updated the app. It seems to run without any error. You can also check my repo to compare your code.
Demo: https://moralisauth.vercel.app/user
GitHub: https://github.com/JohnVersus/demo-apps-nextjs_moralis_auth

Since your app is running without any error on localhost it could also be something related to the env variables added on the vercel. So maybe double-check if the variables related to the next-auth are added correctly.

1 Like

I will clone your repo and try it. Obviously I am doing something wrong. I let you know if I get it right this time.

Thanks

1 Like

By the way, did you use yarn or npm to install the packages ?

I used Yarn with the same yarn.lock file from the tutorial repo.

I used npm and I got a new error… I will try with yarn