@descope/nextjs-sdk 0.10.0 → 0.11.1
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
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# Descope SDK for
|
|
1
|
+
# Descope SDK for Next.js
|
|
2
2
|
|
|
3
|
-
The Descope SDK for
|
|
3
|
+
The Descope SDK for Next.js provides convenient access to the Descope for an application written on top of Next.js. You can read more on the [Descope Website](https://descope.com).
|
|
4
4
|
|
|
5
5
|
This SDK uses under the hood the Descope React SDK and Descope Node SDK
|
|
6
6
|
Refer to the [Descope React SDK](https://github.com/descope/descope-js/tree/main/packages/sdks/react-sdk) and [Descope Node SDK](https://github.com/descope/node-sdk) for more details.
|
|
7
7
|
|
|
8
8
|
## Requirements
|
|
9
9
|
|
|
10
|
-
- The SDK supports
|
|
10
|
+
- The SDK supports Next.js version 13 and above.
|
|
11
11
|
- A Descope `Project ID` is required for using the SDK. Find it on the [project page in the Descope Console](https://app.descope.com/settings/project).
|
|
12
12
|
|
|
13
13
|
## Installing the SDK
|
|
@@ -47,9 +47,9 @@ export default function RootLayout({
|
|
|
47
47
|
}
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
Note: `AuthProvider` uses `sessionTokenViaCookie` by default, in order that the [AuthMiddleware](<#Require-authentication-for-application-(Middleware)>) will work out of the box.
|
|
51
|
-
The session token cookie is set to [`SameSite=Strict
|
|
52
|
-
If you need to customize this, you can set `sessionTokenViaCookie={sameSite: 'Lax'}`
|
|
50
|
+
Note: `AuthProvider` uses `sessionTokenViaCookie={true}` by default, in order that the [AuthMiddleware](<#Require-authentication-for-application-(Middleware)>) will work out of the box.
|
|
51
|
+
The session token cookie is set to [`SameSite=Strict; Secure;`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie) by default.
|
|
52
|
+
If you need to customize this, you can set `sessionTokenViaCookie={sameSite: 'Lax', secure: false}` (if you pass only `sameSite`, `secure` will be set to `true` by default).
|
|
53
53
|
|
|
54
54
|
#### Use Descope to render Flow
|
|
55
55
|
|
|
@@ -131,7 +131,7 @@ const App = () => {
|
|
|
131
131
|
|
|
132
132
|
##### Require authentication for application (Middleware)
|
|
133
133
|
|
|
134
|
-
You can use
|
|
134
|
+
You can use Next.js Middleware to require authentication for a page/route or a group of pages/routes.
|
|
135
135
|
|
|
136
136
|
Descope SDK provides a middleware function that can be used to require authentication for a page/route or a group of pages/routes.
|
|
137
137
|
|
|
@@ -229,7 +229,7 @@ Route handler:
|
|
|
229
229
|
// src/pages/api/routes.ts
|
|
230
230
|
export async function GET() {
|
|
231
231
|
const currSession = await session();
|
|
232
|
-
if (!currSession
|
|
232
|
+
if (!currSession) {
|
|
233
233
|
// ...
|
|
234
234
|
}
|
|
235
235
|
|
|
@@ -238,6 +238,18 @@ export async function GET() {
|
|
|
238
238
|
}
|
|
239
239
|
```
|
|
240
240
|
|
|
241
|
+
The `session()` function uses Next.js's `cookies()` and `headers()` functions to retrieve the session token. If you are using Next.js Version 13, you can use the `getSession(req)` instead.
|
|
242
|
+
|
|
243
|
+
```js
|
|
244
|
+
import { getSession } from '@descope/nextjs-sdk/server';
|
|
245
|
+
|
|
246
|
+
export async function GET(req) {
|
|
247
|
+
const currSession = await getSession(req);
|
|
248
|
+
|
|
249
|
+
// ...
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
241
253
|
##### Optional Parameters
|
|
242
254
|
|
|
243
255
|
If the middleware did not set a session, The `session()` function will attempt to retrieve the session token from cookies and validates it, this requires the project ID to be either set in the environment variables or passed as a parameter to the function.
|
|
@@ -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.
|
|
6
|
+
'x-descope-sdk-version': "0.11.1"
|
|
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.
|
|
4
|
+
'x-descope-sdk-version': "0.11.1"
|
|
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.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "Descope NextJS SDK",
|
|
5
5
|
"author": "Descope Team <info@descope.com>",
|
|
6
6
|
"homepage": "https://github.com/descope/descope-js",
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@descope/node-sdk": "1.6.13",
|
|
67
|
-
"@descope/react-sdk": "2.
|
|
68
|
-
"@descope/web-component": "3.39.
|
|
67
|
+
"@descope/react-sdk": "2.11.1",
|
|
68
|
+
"@descope/web-component": "3.39.2",
|
|
69
69
|
"@descope/core-js-sdk": "2.38.0"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|