Skip to content

Commit fb9ecaa

Browse files
committed
update Refreshing Kinde data section for 2.6.0
1 parent cacb68a commit fb9ecaa

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

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

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,29 +1482,55 @@ if (!(await isAuthenticated())) {
14821482

14831483
Our middleware will automatically refresh the tokens in your session in the background.
14841484

1485-
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.
14861486

1487-
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`.
14881488

1489-
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+
Due to limitations in Next.js, refreshing data on demand can only occur from a client component.
1492+
1493+
For more information, see the [Next.js docs](https://nextjs.org/docs/app/api-reference/functions/cookies#understanding-cookie-behavior-in-server-components).
1494+
1495+
</Aside>
14901496

14911497
<Aside title="Important">
14921498

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

14951502
</Aside>
14961503

14971504
```tsx
1498-
'use server'
1505+
"use client";
14991506

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

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

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

15101536
## Kinde Management API

0 commit comments

Comments
 (0)