Auth0 NextJS get AccessToken without SSR

I was playing with the Auth0 NextJS Sample. It gives sessionToken instead of accessToken. In order to retrieve accessToken, I have to do something as follows:

import { getAccessToken } from '@auth0/nextjs-auth0';
const { accessToken } = await getAccessToken(req, res, {
      scopes: ['read:shows']
});

But the problem is the above code only runs in SSR. I am looking forward for a solution that works purely on CSR. Is there any workaround?

Hi @badpiggie,

Welcome to the Auth0 Community!

Looking at the Auth0 Next.JS SDK, there isn’t a specific sessionToken property, as you shared. The correct property to get an access token should be getAccessToken().

If you need to access the tokens from the client side, you could create an API route to generate the access token securely. Then, call the API route from the client side to get the access token.

Thanks,
Rueben

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.