Next.js Discord

Discord Forum

Protect API endpoint with bearer received after auth0 login

Unanswered
Black and yellow mud dauber posted this in #help-forum
Open in Discord
Black and yellow mud dauberOP
I'm brand new to nextjs and I'm having some problems trying to protect an api endpoint.
Tried a lot of stuff but without success. I am using: NextAuth with Auth0

Initially I tried calling getSession and it works for GET requests, but always returns session = null for POST requests (https://pastebin.com/7e7tg4SB)
One thing I also noticed is that when this error happens I see this error on the terminal https://pasteboard.co/ezeOsaI20vu4.png

Then I tried calling getServerSession inside my handler, but it always returns null (https://pastebin.com/UMG9zZrr)
Also, it gives me this error on the terminal https://pasteboard.co/ILNUgxCBoqrc.png

I checked and I'm passing the bearer token on the requests (this one is for the POST https://pasteboard.co/T0Nxu6xyxPyI.png)
Here is the code where I get this token in my [...nextAuth].js https://pastebin.com/h3HJZ4SC
And here is the code where the token is inserted with Axios interceptor https://pastebin.com/ybHZ6sSp

I'm kinda lost and would be glad for any help.

0 Replies