Skip to content

Commit 8cdf9ac

Browse files
authored
Merge pull request #389 from Yoshify/nextjs/2.6.0
Update docs for Next.js SDK 2.6.0
2 parents 10a0e47 + 45b88e1 commit 8cdf9ac

File tree

1 file changed

+39
-12
lines changed

1 file changed

+39
-12
lines changed

src/content/docs/developer-tools/sdks/backend/nextjs-sdk.mdx

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ You can get an authorized user’s Kinde Auth data from any server component usi
331331
| [`getBooleanFlag`](#getbooleanflag) | Get a boolean feature flag |
332332
| [`getIntegerFlag`](#getintegerflag) | Get an integer feature flag |
333333
| [`getStringFlag`](#getstringflag) | Get a string feature flag |
334-
| [`refreshTokens`](#refreshtokens) | Refresh tokens to get up-to-date Kinde data |
335334
| [`getAccessToken`](#getaccesstoken) | Get the decoded access token |
336335
| [`getAccessTokenRaw`](#getaccesstokenraw) | Get the access token |
337336
| [`getIdToken`](#getidtoken) | Get the decoded ID token |
@@ -1483,29 +1482,57 @@ if (!(await isAuthenticated())) {
14831482

14841483
Our middleware will automatically refresh the tokens in your session in the background.
14851484

1486-
Sometimes, you may want to refresh these tokens yourself. An example of this is when you update Kinde data via the UI or with the Management API.
1485+
Sometimes, you may want to refresh these tokens on demand. An example of this is when you update Kinde data via the UI or with the Management API.
14871486

1488-
To have these updates immediately reflected in your app, you will need to get the most up-to-date Kinde data and then refresh the tokens in your session.
1487+
To immediately get the most up-to-date Kinde data in your session, use the `refreshData` function provided by `useKindeBrowserClient`.
14891488

1490-
To get the most up-to-date Kinde data in your session, use the `refreshTokens` helper function provided by `getKindeServerSession`.
1489+
<Aside title="Warning" type="warning">
1490+
1491+
This utility only works in Next.js 14 and above. Attempting to use it in an older version will result in a warning.
1492+
1493+
Due to limitations in Next.js, refreshing data on demand can only occur from a client component.
1494+
1495+
For more information, see the [Next.js docs](https://nextjs.org/docs/app/api-reference/functions/cookies#understanding-cookie-behavior-in-server-components).
1496+
1497+
</Aside>
14911498

14921499
<Aside title="Important">
14931500

1494-
Due to limitations in Next.js, this will only work in a route handler or server action.
1501+
The `refreshData` function is an asynchronous server action, and it's important to await it
1502+
so that you receive immediate access to the latest data.
14951503

14961504
</Aside>
14971505

14981506
```tsx
1499-
'use server'
1507+
"use client";
15001508

1501-
const handleRefresh = async () => {
1502-
const { refreshTokens } = getKindeServerSession();
1503-
await refreshTokens();
1504-
}
1509+
import { useKindeBrowserClient } from "@kinde-oss/kinde-auth-nextjs";
15051510

1506-
...
1511+
export const UpdatePermissionsButton = () => {
1512+
const { refreshData, getPermissions } = useKindeBrowserClient();
1513+
1514+
const handleUpdatePermissions = async () => {
1515+
// For example purposes, lets say you have an API route that updates the permissions for a user
1516+
await fetch("/api/user/permissions");
1517+
1518+
// Then you can refresh the data and have the changes reflected immediately
1519+
await refreshData();
1520+
1521+
const newPermissions = getPermissions();
15071522

1508-
<button onClick={handleRefresh}>Get up to date data</button>
1523+
// Do something with the new permissions
1524+
// ...
1525+
}
1526+
1527+
return (
1528+
<button
1529+
type="button"
1530+
onClick={handleUpdatePermissions}
1531+
>
1532+
Update Permissions
1533+
</button>
1534+
);
1535+
};
15091536
```
15101537

15111538
## Kinde Management API

0 commit comments

Comments
 (0)