Skip to content

Commit

Permalink
Add Refresh Token advice to the API example (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjmcgrath committed Feb 10, 2021
1 parent b95627d commit e13ed3d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions EXAMPLES.md
Expand Up @@ -218,6 +218,7 @@ export default handleAuth({
try {
await handleLogin(req, res, {
audience: 'https://api.example.com/products', // or AUTH0_AUDIENCE
// Add the `offline_access` scope to also get a Refresh Token
scope: 'openid profile email read:products' // or AUTH0_SCOPE
});
} catch (error) {
Expand All @@ -235,6 +236,8 @@ The API route serves as a proxy between your front end and the external API.
import { getAccessToken, withApiAuthRequired } from '@auth0/nextjs-auth0';

export default withApiAuthRequired(async function products(req, res) {
// If your Access Token is expired and you have a Refresh Token
// `getAccessToken` will fetch you a new one using the `refresh_token` grant
const { accessToken } = await getAccessToken(req, res, {
scopes: ['read:products']
});
Expand Down

0 comments on commit e13ed3d

Please sign in to comment.