I see! a new SDK was just released a couple of weeks abo specifically for Next.js. I’d suggest taking a look at the Next.js Quickstart if you haven’t already: Auth0 Next.js SDK Quickstarts: Login
There is an example in the quickstart of retrieving an Access Token
import { getAccessToken, withApiAuthRequired } from '@auth0/nextjs-auth0';
export default withApiAuthRequired(async function shows(req, res) {
try {
const { accessToken } = await getAccessToken(req, res, {
scopes: ['read:shows']
});
const apiPort = process.env.API_PORT || 3001;
const response = await fetch(`http://localhost:${apiPort}/api/shows`, {
headers: {
Authorization: `Bearer ${accessToken}`
}
});
const shows = await response.json();
res.status(200).json(shows);
} catch (error) {
res.status(error.status || 500).json({ error: error.message });
}
});