I host a backend via Next.js on Vercel. In a separate hosted frontend which is not in the same Next.js repo the user authenticates via Auth0. Therefor, I created a Single Page Application in my Auth0 account. I get the token in the frontend and send it with the API call to the backend. Everything works smoothly. Now I want to protect the backend API.
With Next.js I created a middleware in which I want to validate the token for every API call. The token also arrives. How can I validate the token now?
I have not found a solution that I understood right away.
I created an API in my Auth0 account. In the quick start tutorial, a Node.js solution is shown. Since I use Next.js I didn’t manage to enforce the endpoints via app.use(jwtCheck). I don’t know how to do this because I don’t have access to the express app on Next.js?
All other solutions I found work with the Next.js session. Since my frontend is hosted on another repo separately, I can’t do anything with the solutions.
Hey there @DavidTheo thanks for following up on this one with your solution - That’s correct though, we typically recommend using a library here (jose included) or something like: