// Or, it's slightly more efficient to use the `req`, `res` args if you're // using another part of the SDK like `withApiAuthRequired` or `getSession`. import { NextResponse } from'next/server'; import { getAccessToken, withApiAuthRequired } from'@auth0/nextjs-auth0';
Get an access token to access an external API from the server.
In the App Router:
In a route handler:
In a page or React Server Component:
Note: You can't write to the cookie in a React Server Component, so if the access token is refreshed, it won't be persisted in the session.
You can also get the access token in a page or route in the Edge Runtime:
Note: The Edge runtime features are only supported in the App Router.
In the Page Router:
In an API handler:
In a page:
In middleware: