I’m using Auth0 with a NextJS application using the NextJS SDK and I have the user login set up and working correctly.
I also have an ExpressJS API which I have made an API for in Auth0, and the requests from my NextJS to the ExpressJS API are authenticated and it can get data from it.
In NextJS I have my […auth0].ts set up as:
import { handleAuth, handleLogin } from '@auth0/nextjs-auth0'
export default handleAuth({
login: handleLogin({
authorizationParams: {
audience: process.env.AUTH0_AUDIENCE,
scope: 'openid profile email offline_access',
},
}),
})
And in one of my pages I’m fetching the access token as:
export const getServerSideProps = withPageAuthRequired({
async getServerSideProps(ctx) {
const { accessToken } = await getAccessToken(ctx.req, ctx.res)
console.log(accessToken)
// code to return props
},
})
When I decode the jwt on jwt.io, I see the following data:
{
"iss": "xxx",
"sub": "xxx",
"aud": [
"xxx",
"xxx"
],
"iat": xxx,
"exp": xxx,
"azp": "xxx",
"scope": "openid profile email offline_access",
"permissions": []
}
I’ve checked my logged in user’s Raw JSON in the Auth0 dashboard, and they do have the profile and email data.
What do I need to do get the email, nickname, picture, etc. information in my accessToken in NextJS or my ExpressJS API? I need this information to create an entry in my database with the user information.