@descope/nextjs-sdk 0.15.30 → 0.15.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -127,6 +127,54 @@ const App = () => {
|
|
|
127
127
|
};
|
|
128
128
|
```
|
|
129
129
|
|
|
130
|
+
#### Activity-Based Session Refresh
|
|
131
|
+
|
|
132
|
+
By default, the SDK fires a periodic heartbeat (refresh call) whenever the tab is active. You can opt in to fine-grained control by passing `autoRefresh={{ customActivityTracking: true }}` to `AuthProvider`. With this mode enabled, the SDK only refreshes when `sdk.markUserActive()` has been called since the last refresh — useful for enforcing server-side inactivity timeouts.
|
|
133
|
+
|
|
134
|
+
**Step 1:** Enable it in `AuthProvider`:
|
|
135
|
+
|
|
136
|
+
```tsx
|
|
137
|
+
import { AuthProvider } from '@descope/nextjs-sdk';
|
|
138
|
+
|
|
139
|
+
<AuthProvider projectId="my-project-id" autoRefresh={{ customActivityTracking: true }}>
|
|
140
|
+
<App />
|
|
141
|
+
</AuthProvider>
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
**Step 2:** Call `markUserActive()` on user interactions using the `useDescope` hook from `@descope/nextjs-sdk/client`:
|
|
145
|
+
|
|
146
|
+
```tsx
|
|
147
|
+
'use client';
|
|
148
|
+
import { useEffect } from 'react';
|
|
149
|
+
import { useDescope } from '@descope/nextjs-sdk/client';
|
|
150
|
+
|
|
151
|
+
function useActivityTracking() {
|
|
152
|
+
const sdk = useDescope();
|
|
153
|
+
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
const { markUserActive } = sdk;
|
|
156
|
+
|
|
157
|
+
document.addEventListener('click', markUserActive);
|
|
158
|
+
document.addEventListener('keydown', markUserActive);
|
|
159
|
+
document.addEventListener('touchstart', markUserActive);
|
|
160
|
+
|
|
161
|
+
const onVisibility = () => {
|
|
162
|
+
if (document.visibilityState === 'visible') markUserActive();
|
|
163
|
+
};
|
|
164
|
+
document.addEventListener('visibilitychange', onVisibility);
|
|
165
|
+
|
|
166
|
+
return () => {
|
|
167
|
+
document.removeEventListener('click', markUserActive);
|
|
168
|
+
document.removeEventListener('keydown', markUserActive);
|
|
169
|
+
document.removeEventListener('touchstart', markUserActive);
|
|
170
|
+
document.removeEventListener('visibilitychange', onVisibility);
|
|
171
|
+
};
|
|
172
|
+
}, [sdk]);
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Call `useActivityTracking()` inside a client component rendered within `<AuthProvider>`.
|
|
177
|
+
|
|
130
178
|
#### Trigger Auto Refresh
|
|
131
179
|
|
|
132
180
|
`useSession` triggers a single request to the Descope backend to attempt to refresh the session. If you **don't** `useSession` in your app, the session will not be refreshed automatically. If your app does not require `useSession`, you can trigger the refresh manually by calling `refresh` from `useDescope` hook. Example:
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const DESCOPE_SESSION_HEADER = 'x-descope-session';
|
|
4
4
|
const baseHeaders = {
|
|
5
5
|
'x-descope-sdk-name': 'nextjs',
|
|
6
|
-
'x-descope-sdk-version': "0.15.
|
|
6
|
+
'x-descope-sdk-version': "0.15.32"
|
|
7
7
|
};
|
|
8
8
|
const DEFAULT_PUBLIC_ROUTES = {
|
|
9
9
|
signIn: process.env.SIGN_IN_ROUTE || '/sign-in',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const DESCOPE_SESSION_HEADER = 'x-descope-session';
|
|
2
2
|
const baseHeaders = {
|
|
3
3
|
'x-descope-sdk-name': 'nextjs',
|
|
4
|
-
'x-descope-sdk-version': "0.15.
|
|
4
|
+
'x-descope-sdk-version': "0.15.32"
|
|
5
5
|
};
|
|
6
6
|
const DEFAULT_PUBLIC_ROUTES = {
|
|
7
7
|
signIn: process.env.SIGN_IN_ROUTE || '/sign-in',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@descope/nextjs-sdk",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.32",
|
|
4
4
|
"description": "Descope NextJS SDK",
|
|
5
5
|
"author": "Descope Team <info@descope.com>",
|
|
6
6
|
"homepage": "https://github.com/descope/descope-js",
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@descope/node-sdk": "1.10.0",
|
|
67
|
-
"@descope/react-sdk": "2.
|
|
68
|
-
"@descope/
|
|
69
|
-
"@descope/
|
|
67
|
+
"@descope/react-sdk": "2.28.1",
|
|
68
|
+
"@descope/web-component": "3.64.0",
|
|
69
|
+
"@descope/core-js-sdk": "2.62.0"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@babel/core": "7.26.0",
|