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: packages/sdks/nextjs-sdk/README.md
+17-5
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
-
# Descope SDK for NextJS
1
+
# Descope SDK for Next.js
2
2
3
-
The Descope SDK for NextJS provides convenient access to the Descope for an application written on top of NextJS. You can read more on the [Descope Website](https://descope.com).
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 NextJS version 13 and above.
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
@@ -131,7 +131,7 @@ const App = () => {
131
131
132
132
##### Require authentication for application (Middleware)
133
133
134
-
You can use NextJS Middleware to require authentication for a page/route or a group of pages/routes.
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
exportasyncfunctionGET() {
231
231
constcurrSession=awaitsession();
232
-
if (!currSession.isAuthenticated) {
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.
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.
0 commit comments