Next.js Discord

Discord Forum

Receiving a 403 (forbidden) error from my Credentials Provider

Unanswered
Southern yellowjacket posted this in #help-forum
Open in Discord
Southern yellowjacketOP
I am using next auth. upon building the app it works fine but after few hours it start giving me 403 even csrf of next auth returns 200

this is my code

12 Replies

@Southern yellowjacket I am using next auth. upon building the app it works fine but after few hours it start giving me 403 even csrf of next auth returns 200 this is my code
you are trying to handle the expires of your jwt tokens on your own. However, next-auth already does it for you. And you also already added it in your code:
session: {
    strategy: "jwt",
    maxAge: 30 * 24 * 60 * 60,
    updateAge: 24 * 60 * 60,
  },

So just remove your custom expire logic and next-auth will do the rest for you
Southern yellowjacketOP
will this resolve the issue of 403 on sign in and signout issue that happens after i start the pm2 service
that should be the case. In my head the issue is right now, that the token expires too early and next-auth thinks that its still there (as its still here - just expired) and like that does not redirect like expected
Southern yellowjacketOP
I am confused this issue only presist in production. i had it perfectly runiing on dev and local.
Southern yellowjacketOP
I've tested this
Some people also doing weird stuff like this:
NEXTAUTH_SECRET=$(openssl rand -base64 64)

Instead of generating a new one everytime, use a static one (pls dev & prod different ones)
Southern yellowjacketOP
Ok let me test this
Southern yellowjacketOP
this solution doesn't work either
It’s pretty hard for me to determine the exact issue. If you can provide a repo that reproduces the issue, send it into this thread and we can have a look on it in detail and test stuff, while you are doing something else
Southern yellowjacketOP
actualy this issue only presist in my production enviroment. it works fine in local and dev enviroment
Then it’s impossible for us to help you out there without having a reproduction of the clear issue