Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: next.js readme #1047

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions packages/sdks/nextjs-sdk/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Descope SDK for NextJS
# Descope SDK for Next.js

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).
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).

This SDK uses under the hood the Descope React SDK and Descope Node SDK
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.

## Requirements

- The SDK supports NextJS version 13 and above.
- The SDK supports Next.js version 13 and above.
- 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).

## Installing the SDK
Expand Down Expand Up @@ -131,7 +131,7 @@ const App = () => {

##### Require authentication for application (Middleware)

You can use NextJS Middleware to require authentication for a page/route or a group of pages/routes.
You can use Next.js Middleware to require authentication for a page/route or a group of pages/routes.

Descope SDK provides a middleware function that can be used to require authentication for a page/route or a group of pages/routes.

Expand Down Expand Up @@ -229,7 +229,7 @@ Route handler:
// src/pages/api/routes.ts
export async function GET() {
const currSession = await session();
if (!currSession.isAuthenticated) {
if (!currSession) {
// ...
}

Expand All @@ -238,6 +238,18 @@ export async function GET() {
}
```

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.

```js
import { getSession } from '@descope/nextjs-sdk/server';

export async function GET(req) {
const currSession = await getSession(req);

// ...
}
```

##### Optional Parameters

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.
Expand Down
Loading