You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: EXAMPLES.md
+59Lines changed: 59 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -520,6 +520,65 @@ export async function middleware(request: NextRequest) {
520
520
}
521
521
```
522
522
523
+
### Forcing Access Token Refresh
524
+
525
+
In some scenarios, you might need to explicitly force the refresh of an access token, even if it hasn't expired yet. This can be useful if, for example, the user's permissions or scopes have changed and you need to ensure the application has the latest token reflecting these changes.
526
+
527
+
The `getAccessToken` method provides an option to force this refresh.
528
+
529
+
**App Router (Server Components, Route Handlers, Server Actions):**
530
+
531
+
When calling `getAccessToken` without request and response objects, you can pass an options object as the first argument. Set the `refresh` property to `true` to force a token refresh.
returnResponse.json({ error: 'Failed to get access token' }, { status: 500 });
547
+
}
548
+
}
549
+
```
550
+
551
+
**Pages Router (getServerSideProps, API Routes):**
552
+
553
+
When calling `getAccessToken` with request and response objects (from `getServerSideProps` context or an API route), the options object is passed as the third argument.
By setting `{ refresh: true }`, you instruct the SDK to bypass the standard expiration check and request a new access token from the identity provider using the refresh token (if available and valid). The new token set (including the potentially updated access token, refresh token, and expiration time) will be saved back into the session automatically.
580
+
This will in turn, update the `access_token`, `id_token` and `expires_at` fields of `tokenset` in the session.
0 commit comments