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

add js backend sdk guide, deprecated warnings, comments to refactor code #1654

Merged
merged 4 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
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
89 changes: 89 additions & 0 deletions docs/backend-requests/handling/js-backend-sdks.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
title: Handling requests with a JS Backend SDK
description: Learn how to handle authenticated requests with one of Clerk's JS Backend SDKs.
---

To handle authenticated requests, use one of the following JS Backend SDKs.

## Clerk Express SDK

The `clerkMiddleware()` function checks the request's cookies and headers for a session JWT. If the user has a valid session, the `clerkMiddleware()` function attaches the [properties](/docs/references/nextjs/auth-object#auth-object-properties) of the authenticated user to the request object.

```js
import { clerkMiddleware } from '@clerk/express'

const app = express()

// Pass no parameters
app.use(clerkMiddleware())

// Pass options
app.use(clerkMiddleware(options))
```

For more information on the Middleware functions and SDK features, see the [Express SDK](/docs/references/express/overview) page.

## Clerk Fastify SDK

The `clerkPlugin` checks the request's cookies and headers for a session JWT. If the user has a valid session, the `clerkPlugin` attaches the [properties](/docs/references/nextjs/auth-object#auth-object-properties) of the authenticated user to the request object.

```ts
import 'dotenv/config'
import Fastify from 'fastify'
import { clerkClient, clerkPlugin, getAuth } from '@clerk/fastify'

const fastify = Fastify({ logger: true })

fastify.register(clerkPlugin)

fastify.get('/', async (request, reply) => {
const { userId } = getAuth(request)

// Protect the route from unauthenticated users
if (!userId) {
return reply.code(403).send({ error: 'Unauthorized request.' })
}

const user = userId ? await clerkClient.users.getUser(userId) : null

return reply.send({
message: 'User retrieved successfully.',
user,
})
})

const start = async () => {
try {
await fastify.listen({ port: 8080 })
} catch (error) {
fastify.log.error(error)
process.exit(1)
}
}

start()
```

For more information on the Clerk plugin and SDK features, see the [Fastify SDK](/docs/quickstarts/fastify) page.

## Clerk Backend SDK

If you're not using Express or Fastify, use the `@clerk/backend` package to access `clerkClient`.

```ts
import { createClerkClient } from '@clerk/backend'

const clerkClient = createClerkClient({
secretKey: process.env.CLERK_SECRET_KEY,
publishableKey: process.env.CLERK_PUBLISHABLE_KEY,
})

const { isSignedIn } = await clerkClient.authenticateRequest(req, {
jwtKey: process.env.CLERK_JWT_KEY,
authorizedParties: ['https://example.com'],
})

if (!isSignedIn) {
return Response.json({ status: 401 })
}
```
8 changes: 6 additions & 2 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,8 @@
"items": [
[
{
"title": "Node.js & Express",
"href": "/docs/backend-requests/handling/nodejs"
"title": "JS Backend SDKs",
"href": "/docs/backend-requests/handling/js-backend-sdks"
},
{
"title": "Go",
Expand All @@ -718,6 +718,10 @@
{
"title": "Manual JWT Verification",
"href": "/docs/backend-requests/handling/manual-jwt"
},
{
"title": "Node.js (Deprecated)",
"href": "/docs/backend-requests/handling/nodejs"
}
]
]
Expand Down
5 changes: 5 additions & 0 deletions docs/references/backend/sessions/get-token.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ _Token {
</Tab>

<Tab>
> [!CAUTION]
> On January 8, 2025, the Node SDK will no longer be available. [Upgrade to the Express SDK.](/docs/upgrade-guides/node-to-express)

{/* TODO: Update Node example - SDK is being deprecated */}

```js {{ filename: 'getToken.ts' }}
import { clerkClient } from '@clerk/clerk-sdk-node'

Expand Down
5 changes: 5 additions & 0 deletions docs/references/backend/user/update-user.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ _User {
</Tab>

<Tab>
> [!CAUTION]
> On January 8, 2025, the Node SDK will no longer be available. [Upgrade to the Express SDK.](/docs/upgrade-guides/node-to-express)

{/* TODO: Update Node example - SDK is being deprecated */}

```js {{ filename: 'updateUser.js' }}
import { clerkClient } from '@clerk/clerk-sdk-node'

Expand Down
3 changes: 3 additions & 0 deletions docs/upgrade-guides/core-2/backend.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ The `orgs` claim was part of the `JwtPayload`. Here are a few examples of where
</AccordionPanel>

<AccordionPanel>
> [!CAUTION]
> On January 8, 2025, the Node SDK will no longer be available. [Upgrade to the Express SDK.](/docs/upgrade-guides/node-to-express)

```typescript {{ filename: '@clerk/clerk-sdk-node' }}
import { clerkClient } from '@clerk/clerk-sdk-node'

Expand Down
3 changes: 3 additions & 0 deletions docs/upgrade-guides/core-2/chrome-extension.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ The `orgs` claim was part of the `JwtPayload`. Here are a few examples of where
</AccordionPanel>

<AccordionPanel>
> [!CAUTION]
> On January 8, 2025, the Node SDK will no longer be available. [Upgrade to the Express SDK.](/docs/upgrade-guides/node-to-express)

```typescript {{ filename: '@clerk/clerk-sdk-node' }}
import { clerkClient } from '@clerk/clerk-sdk-node'

Expand Down
3 changes: 3 additions & 0 deletions docs/upgrade-guides/core-2/expo.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ The `orgs` claim was part of the `JwtPayload`. Here are a few examples of where
</AccordionPanel>

<AccordionPanel>
> [!CAUTION]
> On January 8, 2025, the Node SDK will no longer be available. [Upgrade to the Express SDK.](/docs/upgrade-guides/node-to-express)

```typescript {{ filename: '@clerk/clerk-sdk-node' }}
import { clerkClient } from '@clerk/clerk-sdk-node'

Expand Down
3 changes: 3 additions & 0 deletions docs/upgrade-guides/core-2/fastify.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ The `orgs` claim was part of the `JwtPayload`. Here are a few examples of where
</AccordionPanel>

<AccordionPanel>
> [!CAUTION]
> On January 8, 2025, the Node SDK will no longer be available. [Upgrade to the Express SDK.](/docs/upgrade-guides/node-to-express)

```typescript {{ filename: '@clerk/clerk-sdk-node' }}
import { clerkClient } from '@clerk/clerk-sdk-node'

Expand Down
3 changes: 3 additions & 0 deletions docs/upgrade-guides/core-2/javascript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ The `orgs` claim was part of the `JwtPayload`. Here are a few examples of where
</AccordionPanel>

<AccordionPanel>
> [!CAUTION]
> On January 8, 2025, the Node SDK will no longer be available. [Upgrade to the Express SDK.](/docs/upgrade-guides/node-to-express)

```typescript {{ filename: '@clerk/clerk-sdk-node' }}
import { clerkClient } from '@clerk/clerk-sdk-node'

Expand Down
9 changes: 9 additions & 0 deletions docs/upgrade-guides/core-2/nextjs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ As part of this release, some of the top-level exports of `@clerk/nextjs` have b
</AccordionPanel>

<AccordionPanel>
> [!CAUTION]
> On January 8, 2025, the Node SDK will no longer be available. [Upgrade to the Express SDK.](/docs/upgrade-guides/node-to-express)

The `@clerk/nextjs/api` subpath was removed completely. It re-exported helpers from `@clerk/clerk-sdk-node` and its types. If you relied on these, import from `@clerk/clerk-sdk-node` directly instead.

```js {{ prettier: false, del: [8, 11], ins: [9, 12] }}
Expand Down Expand Up @@ -526,6 +529,9 @@ The `orgs` claim was part of the `JwtPayload`. Here are a few examples of where
</AccordionPanel>

<AccordionPanel>
> [!CAUTION]
> On January 8, 2025, the Node SDK will no longer be available. [Upgrade to the Express SDK.](/docs/upgrade-guides/node-to-express)

```typescript {{ filename: '@clerk/clerk-sdk-node' }}
import { clerkClient } from '@clerk/clerk-sdk-node'

Expand Down Expand Up @@ -737,6 +743,9 @@ As part of this major version, a number of previously deprecated props, argument
</AccordionPanel>

<AccordionPanel>
> [!CAUTION]
> On January 8, 2025, the Node SDK will no longer be available. [Upgrade to the Express SDK.](/docs/upgrade-guides/node-to-express)

The import subpath `@clerk/nextjs/api` has been removed. This includes the following imports:

```js
Expand Down
5 changes: 4 additions & 1 deletion docs/upgrade-guides/core-2/node.mdx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
---
title: Upgrading `@clerk/clerk-sdk-node` to Core 2
description: "Learn how to upgrade Clerk's Node SDK to the lastest version."
description: "Learn how to upgrade Clerk's Node SDK to the latest version."
---

> [!CAUTION]
> On January 8, 2025, the Node SDK will no longer be available. [Upgrade to the Express SDK.](/docs/upgrade-guides/node-to-express)

{/* WARNING: This is a generated file and should not be edited directly. To update its contents, see the "upgrade" package in the clerk/javascript repo. */}

Core 2 is included in the Node.js SDK starting with version 5. This new version ships with a variety of smaller DX improvements and housekeeping items. Each of the potentially breaking changes are detailed in this guide, below.
Expand Down
3 changes: 3 additions & 0 deletions docs/upgrade-guides/core-2/react.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ The `orgs` claim was part of the `JwtPayload`. Here are a few examples of where
</AccordionPanel>

<AccordionPanel>
> [!CAUTION]
> On January 8, 2025, the Node SDK will no longer be available. [Upgrade to the Express SDK.](/docs/upgrade-guides/node-to-express)

```typescript {{ filename: '@clerk/clerk-sdk-node' }}
import { clerkClient } from '@clerk/clerk-sdk-node'

Expand Down
3 changes: 3 additions & 0 deletions docs/upgrade-guides/core-2/remix.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ The `orgs` claim was part of the `JwtPayload`. Here are a few examples of where
</AccordionPanel>

<AccordionPanel>
> [!CAUTION]
> On January 8, 2025, the Node SDK will no longer be available. [Upgrade to the Express SDK.](/docs/upgrade-guides/node-to-express)

```typescript {{ filename: '@clerk/clerk-sdk-node' }}
import { clerkClient } from '@clerk/clerk-sdk-node'

Expand Down
5 changes: 5 additions & 0 deletions docs/users/creating-users.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ To create users using the Clerk API, you can use the [`createUser()`](/docs/refe
</Tab>

<Tab>
> [!CAUTION]
> On January 8, 2025, the Node SDK will no longer be available. [Upgrade to the Express SDK.](/docs/upgrade-guides/node-to-express)

{/* TODO: Update Node example - SDK is being deprecated */}

```ts {{ filename: 'create-user.ts' }}
import { clerkClient } from '@clerk/clerk-sdk-node'

Expand Down
5 changes: 5 additions & 0 deletions docs/users/deleting-users.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ To delete users using the Clerk API, you can use the [`deleteUser()`](/docs/refe
</Tab>

<Tab>
> [!CAUTION]
> On January 8, 2025, the Node SDK will no longer be available. [Upgrade to the Express SDK.](/docs/upgrade-guides/node-to-express)

{/* TODO: Update Node example - SDK is being deprecated */}

```ts {{ filename: 'delete-user.ts' }}
import { clerkClient } from '@clerk/clerk-sdk-node'

Expand Down
20 changes: 20 additions & 0 deletions docs/users/metadata.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ Private metadata is only accessible by the backend, which makes this useful for
</Tab>

<Tab>
> [!CAUTION]
> On January 8, 2025, the Node SDK will no longer be available. [Upgrade to the Express SDK.](/docs/upgrade-guides/node-to-express)

{/* TODO: Update Node example - SDK is being deprecated */}

```ts {{ filename: 'private.ts' }}
import { clerkClient } from '@clerk/clerk-sdk-node'

Expand Down Expand Up @@ -154,6 +159,11 @@ You can retrieve the private metadata for a user by using the [`getUser`](/docs/
</Tab>

<Tab>
> [!CAUTION]
> On January 8, 2025, the Node SDK will no longer be available. [Upgrade to the Express SDK.](/docs/upgrade-guides/node-to-express)

{/* TODO: Update Node example - SDK is being deprecated */}

```ts {{ filename: 'private.ts' }}
import { clerkClient } from '@clerk/clerk-sdk-node'

Expand Down Expand Up @@ -242,6 +252,11 @@ Public metadata is accessible by both the frontend and the backend, but can only
</Tab>

<Tab>
> [!CAUTION]
> On January 8, 2025, the Node SDK will no longer be available. [Upgrade to the Express SDK.](/docs/upgrade-guides/node-to-express)

{/* TODO: Update Node example - SDK is being deprecated */}

```ts {{ filename: 'public.ts' }}
import { clerkClient } from '@clerk/clerk-sdk-node'

Expand Down Expand Up @@ -363,6 +378,11 @@ Updating this value overrides the previous value; it does not merge. To perform
</Tab>

<Tab>
> [!CAUTION]
> On January 8, 2025, the Node SDK will no longer be available. [Upgrade to the Express SDK.](/docs/upgrade-guides/node-to-express)

{/* TODO: Update Node example - SDK is being deprecated */}

```ts {{ filename: 'private.ts' }}
import { clerkClient } from '@clerk/clerk-sdk-node'

Expand Down
5 changes: 5 additions & 0 deletions docs/users/user-impersonation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ To detect impersonated sessions in the frontend, the `actor` object contains the
</Tab>

<Tab>
> [!CAUTION]
> On January 8, 2025, the Node SDK will no longer be available. [Upgrade to the Express SDK.](/docs/upgrade-guides/node-to-express)

{/* TODO: Update Node example - SDK is being deprecated */}

The Node.js SDK provides a [middleware](/docs/backend-requests/handling/nodejs) that augments the request object with the authentication context.

```js
Expand Down
Loading