Auth0 Home Blog Docs

Next.js Authentication Tutorial

javascript
nextjs
#1

Learn how to add authentication to your Next.js application with Passport

Read on :v:

Brought to you by @bruno.krebs :man_technologist:t5:

#2

Next.js and Passport, great combination, huh?

#3

Great article, thank you!
I’m trying building an architecture with different services and all authenticate with Auth0. I Was wondering if I somehow can access the access token from the browser, so I can make requests to those API’s. (Not in the same project as the server.js File and not on the same host).

I was trying to use Implicit Flow at first but that didn’t work so well with NextJS. How can I have the user’s accessToken in the browser with this approach?

1 Like
#4

Thanks for the great article!

However, I am not sure why you have to create src/state at first because it is not used at all.
I assume that you have re-written the article using React hooks or something?

1 Like
#5

Hey there, @timojokinen.

You can easily fetch an access token for an API by configuring the audience property on the Passport Auth0 strategy. I built a sample to show that: https://github.com/auth0-blog/nextjs-passport/pull/1/files

Note, however, that it is not a good idea to let the token leak to the browser. Use it on the backend only and fetch the API from there. That’s why I use delete user.accessToken.

I hope that helps.

Node.js and Express Tutorial: Building and Securing RESTful APIs
#6

Oh, yeah, very true. These are remnants of a previous version. I will remove it. Thanks for the heads up :slightly_smiling_face: