This TypeScript code sample demonstrates how to implement authorization in a NestJS API server using Auth0.
There is an issue with the .env environment names in the instructions and in the code.
In the instructions:
PORT=6060 CLIENT_ORIGIN_URL=http://localhost:4040 AUTH0_AUDIENCE=AUTH0-AUDIENCE AUTH0_DOMAIN=AUTH0-DOMAIN
To get the app to start .env needs:
PORT=6060 CLIENT_ORIGIN_URL=http://localhost:4040 AUTH0_AUDIENCE=https://hello-world.example.com AUTH0_DOMAIN=AUTH0-DOMAIN ISSUER_BASE_URL=https://AUTH0-DOMAIN AUDIENCE=https://hello-world.example.com
If I use the token from the response on my API Details page I get invalid token.
Is there a way to debug what is wrong?
Thank you so much for reporting this. You are correct. There was a mistake during the document release process. We have corrected that and the code sample page now shows the correct content for the
PORT=6060 ISSUER_BASE_URL=https://AUTH0-DOMAIN AUDIENCE=AUTH0-AUDIENCE CLIENT_ORIGIN_URL=http://localhost:4040
Apologies for that mix up.
Are you referring to the test access token that you get as part of the code sample page instructions or one that you are getting by using a client application to test the API?
Thanks for the revised .env settings. The ‘get protected’ route is now working
Hi when use the typescriopt v18 react code version I get the below error on npm install
Even if I login into npm I get the same error message.
That’s great! I am glad to hear.
Can you please share the URL of the repo that you are using, please?
This is the spa-repo.
It is a checkout of the auth0 react v18 typescript example. I m using this as I will be updating a nextJs v13 front end.
Thanks for your response. That’s a quick fix: Please delete the
package-lock.json from that sample project and run
npm install again. Thanks!
Hi - I found that my npm certificate had expired. Following the above and generating new ones worked a treat thanks.
Glad to hear! Thanks for trying out our different code samples and blog posts!
Is there a blog that deals with sending messages (hopefully POST) from nextJs protected API route to nestJs API.
I am currently getting an unauthorised error using the token from in NextJs. If I run a test using Postman and the test JWT it succeeds. The code in NestJS follows the messaages code from this tutorial.
If helpful here is the github repo
We don’t have a resource like that. A few questions to help troubleshoot:
- How are you getting the access token on your Next.js API route?
- Are both Next.js web app and NestJS API registered under the same Auth0 tenant?
- How are you setting the API audience in your Next.js API? Is it the same audience as your NestJS API?
Thanks for your help- typo in audience