-
Couldn't load subscription status.
- Fork 851
Add SDK-specificity to Authentication flows, User management, and Session management sections #2595
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
base: main
Are you sure you want to change the base?
Changes from all commits
4fd7d1b
28f40e2
b62ccef
edeef17
f288985
4349075
c3d5cc2
7da6b58
d41ab9f
be7e558
e8fb05c
b22f559
c32a424
7c8f48b
b919b0f
794d218
8797e04
6d75db8
2db149f
15b54b6
e832559
580f0d0
d1c0c09
5e5ef6e
a33d50d
fe30e22
7d67070
cc98875
7a87a82
541bf8a
42d6bcb
b71d39e
96ccc3f
f8f506a
bf0026e
9377180
c434319
5827704
bd05a97
7ae4daf
2f5f2e9
c3348ad
7e05441
d231049
4f48151
0ab77c3
3f0ec0e
1bda73f
500b336
87c788b
9bbb93f
51c86a7
3d00b81
c103b38
a8bd645
9400d54
e3eeb89
74e96bf
d0549f6
e829efa
eac33c7
18b1898
4fcfe36
3b3a8d5
bbbb565
b90d128
825a0d7
698e41b
f87faa4
bd7dfe2
6aec942
62a34cd
e0823a6
0e9478d
96161c2
912e4fa
f925265
3419146
d9756c8
8476eb9
8995b38
c1740ff
dcee2df
9368799
06b2d79
e971241
209df91
466a643
ad2f086
02a2fe2
82a3cdc
5e567d8
9e863e6
9509ac9
f5b6de8
6856708
f03e7a2
d9ec3f7
4eab2c2
17677ee
3ec227a
2e4e94f
8ab135b
02551ab
69fe2e9
2bd1103
09e289e
cd49816
da74a31
2f387af
528675a
f76773a
134b0ce
c665602
bba66e5
7bccc35
cb5d620
1f248fc
509e427
04cf52c
d28a08c
e72ee65
dfb3e9d
d5e5c5b
2ed4340
4c071e8
1e2d953
bb84458
775a75a
3808510
e4a6b8f
164631a
5981b6e
2df6042
65fe762
f680ed3
91bb42a
27ee75d
e19f105
c588a8a
743c184
91cc63b
dcdc79f
e199eb0
b0273b4
d7520b0
83e78ee
d244404
92cb51a
0cfe90f
f143337
2e95154
8f2178f
aaa05f8
9736376
7c76899
8078a42
325b157
6e8accf
aecff1a
2b94dec
536b458
bbde109
81eb2cb
c67f575
2a4798d
54fef82
560a350
248e98c
fe0aa87
e576e69
25dc568
1705d2b
906510e
34dc91b
c56535e
02a7f8b
d91f5d2
0c03196
b7b0854
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| > [!NOTE] | ||
| > Importing `clerkClient` varies based on your framework. Refer to the [JS Backend SDK overview](/docs/js-backend/getting-started/quickstart) for usage details, including guidance on [how to access the `userId` and other properties](/docs/js-backend/getting-started/quickstart#get-the-user-id-and-other-properties). | ||
| > Using `clerkClient` varies based on your framework. Refer to the [JS Backend SDK overview](/docs/js-backend/getting-started/quickstart) for usage details, including guidance on [how to access the `userId` and other properties](/docs/js-backend/getting-started/quickstart#get-the-user-id-and-other-properties). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| <Tabs items={["Next.js", "Astro", "Express", "React Router", "Tanstack React Start"]}> | ||
| <Tab> | ||
| ```ts {{ filename: 'app/api/example/route.ts' }} | ||
| import { clerkClient } from '@clerk/nextjs/server' | ||
| import { NextResponse } from 'next/server' | ||
|
|
||
| export async function GET() { | ||
| try { | ||
| const client = await clerkClient() | ||
| const invitation = await client.invitations.createInvitation({ | ||
| emailAddress: '[email protected]', | ||
| redirectUrl: 'https://www.example.com/my-sign-up', | ||
| publicMetadata: { | ||
| example: 'metadata', | ||
| example_nested: { | ||
| nested: 'metadata', | ||
| }, | ||
| }, | ||
| }) | ||
| return NextResponse.json({ message: 'Invitation created', invitation }) | ||
| } catch (error) { | ||
| console.log(error) | ||
| return NextResponse.json({ error: 'Error creating invitation' }) | ||
| } | ||
| } | ||
| ``` | ||
| </Tab> | ||
|
|
||
| <Tab> | ||
| ```tsx {{ filename: 'src/api/example.ts' }} | ||
| import type { APIRoute } from 'astro' | ||
| import { clerkClient } from '@clerk/astro/server' | ||
|
|
||
| export const GET: APIRoute = async (context) => { | ||
| await clerkClient(context).invitations.createInvitation({ | ||
| emailAddress: '[email protected]', | ||
| redirectUrl: 'https://www.example.com/my-sign-up', | ||
| publicMetadata: { | ||
| example: 'metadata', | ||
| example_nested: { | ||
| nested: 'metadata', | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| return new Response(JSON.stringify({ success: true }), { status: 200 }) | ||
| } | ||
| ``` | ||
| </Tab> | ||
|
|
||
| <Tab> | ||
| ```ts {{ filename: 'public.ts' }} | ||
| import { getAuth, clerkClient } from '@clerk/express' | ||
|
|
||
| app.post('/createUser', async (req, res) => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only
|
||
| await clerkClient.invitations.createInvitation({ | ||
| emailAddress: '[email protected]', | ||
| redirectUrl: 'https://www.example.com/my-sign-up', | ||
| publicMetadata: { | ||
| example: 'metadata', | ||
| example_nested: { | ||
| nested: 'metadata', | ||
| }, | ||
| }, | ||
| password: 'password', | ||
| }) | ||
|
|
||
| res.status(200).json({ success: true }) | ||
| }) | ||
| ``` | ||
| </Tab> | ||
|
|
||
| <Tab> | ||
| ```tsx {{ filename: 'app/routes/example.tsx' }} | ||
| import { clerkClient } from '@clerk/react-router/server' | ||
| import type { Route } from './+types/example' | ||
|
|
||
| export async function loader(args: Route.LoaderArgs) { | ||
| await clerkClient.invitations.createInvitation({ | ||
| emailAddress: '[email protected]', | ||
| redirectUrl: 'https://www.example.com/my-sign-up', | ||
| publicMetadata: { | ||
| example: 'metadata', | ||
| example_nested: { | ||
| nested: 'metadata', | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| return { success: true } | ||
| } | ||
| ``` | ||
| </Tab> | ||
|
|
||
| <Tab> | ||
| ```tsx {{ filename: 'app/routes/api/example.tsx' }} | ||
| import { json } from '@tanstack/react-start' | ||
| import { createFileRoute } from '@tanstack/react-router' | ||
| import { clerkClient } from '@clerk/tanstack-react-start/server' | ||
|
|
||
| export const ServerRoute = createFileRoute('/api/example')({ | ||
| server: { | ||
| handlers: { | ||
| GET: async () => { | ||
| await clerkClient().invitations.createInvitation({ | ||
| emailAddress: '[email protected]', | ||
| redirectUrl: 'https://www.example.com/my-sign-up', | ||
| publicMetadata: { | ||
| example: 'metadata', | ||
| example_nested: { | ||
| nested: 'metadata', | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| return json({ success: true }) | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| ``` | ||
| </Tab> | ||
| </Tabs> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| <Tabs items={["Next.js", "Astro", "Express", "React Router", "Tanstack React Start"]}> | ||
| <Tab> | ||
| ```ts {{ filename: 'app/api/example/route.ts' }} | ||
| import { auth, clerkClient } from '@clerk/nextjs/server' | ||
| import { NextResponse } from 'next/server' | ||
|
|
||
| export async function GET() { | ||
| try { | ||
| const client = await clerkClient() | ||
| const user = await client.users.createUser({ | ||
| emailAddress: ['[email protected]'], | ||
| password: 'password', | ||
| }) | ||
| return NextResponse.json({ message: 'User created', user }) | ||
| } catch (error) { | ||
| console.log(error) | ||
| return NextResponse.json({ error: 'Error creating user' }) | ||
| } | ||
| } | ||
| ``` | ||
| </Tab> | ||
|
|
||
| <Tab> | ||
| ```tsx {{ filename: 'src/api/example.ts' }} | ||
| import type { APIRoute } from 'astro' | ||
| import { clerkClient } from '@clerk/astro/server' | ||
|
|
||
| export const GET: APIRoute = async (context) => { | ||
| await clerkClient(context).users.createUser({ | ||
| emailAddress: ['[email protected]'], | ||
| password: 'password', | ||
| }) | ||
|
|
||
| return new Response(JSON.stringify({ success: true }), { status: 200 }) | ||
| } | ||
| ``` | ||
| </Tab> | ||
|
|
||
| <Tab> | ||
| ```ts {{ filename: 'public.ts' }} | ||
| import { getAuth, clerkClient } from '@clerk/express' | ||
|
|
||
| app.post('/createUser', async (req, res) => { | ||
| await clerkClient.users.createUser({ | ||
| emailAddress: ['[email protected]'], | ||
| password: 'password', | ||
| }) | ||
|
|
||
| res.status(200).json({ success: true }) | ||
| }) | ||
| ``` | ||
| </Tab> | ||
|
|
||
| <Tab> | ||
| ```tsx {{ filename: 'app/routes/example.tsx' }} | ||
| import { clerkClient, getAuth } from '@clerk/react-router/server' | ||
| import type { Route } from './+types/example' | ||
|
|
||
| export async function loader(args: Route.LoaderArgs) { | ||
| await clerkClient.users.createUser({ | ||
| emailAddress: ['[email protected]'], | ||
| password: 'password', | ||
| }) | ||
|
|
||
| return { success: true } | ||
| } | ||
| ``` | ||
| </Tab> | ||
|
|
||
| <Tab> | ||
| ```tsx {{ filename: 'app/routes/api/example.tsx' }} | ||
| import { json } from '@tanstack/react-start' | ||
| import { createFileRoute } from '@tanstack/react-router' | ||
| import { clerkClient } from '@clerk/tanstack-react-start/server' | ||
|
|
||
| export const ServerRoute = createFileRoute('/api/example')({ | ||
| server: { | ||
| handlers: { | ||
| GET: async () => { | ||
| await clerkClient().users.createUser({ | ||
| emailAddress: ['[email protected]'], | ||
| password: 'my-secure-password', | ||
| }) | ||
|
|
||
| return json({ success: true }) | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| ``` | ||
| </Tab> | ||
| </Tabs> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| <Tabs items={["Next.js", "Astro", "Express", "React Router", "Tanstack React Start"]}> | ||
| <Tab> | ||
| ```ts {{ filename: 'app/api/example/route.ts' }} | ||
| import { auth, clerkClient } from '@clerk/nextjs/server' | ||
| import { NextResponse } from 'next/server' | ||
|
|
||
| export async function GET() { | ||
| const { userId } = await auth() | ||
|
|
||
| await clerkClient.users.deleteUser(userId) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't all of these examples deleting yourself (the current logged in user)? |
||
|
|
||
| return NextResponse.json({ success: true }) | ||
| } | ||
| ``` | ||
| </Tab> | ||
|
|
||
| <Tab> | ||
| ```tsx {{ filename: 'src/api/example.ts' }} | ||
| import type { APIRoute } from 'astro' | ||
| import { clerkClient } from '@clerk/astro/server' | ||
|
|
||
| export const GET: APIRoute = async (context) => { | ||
| const { userId } = context.locals.auth() | ||
|
|
||
| await clerkClient(context).users.deleteUser(userId) | ||
|
|
||
| return new Response(JSON.stringify({ success: true }), { status: 200 }) | ||
| } | ||
| ``` | ||
| </Tab> | ||
|
|
||
| <Tab> | ||
| ```ts {{ filename: 'public.ts' }} | ||
| import { getAuth, clerkClient } from '@clerk/express' | ||
|
|
||
| app.post('/deleteUser', async (req, res) => { | ||
| const { userId } = getAuth(req) | ||
|
|
||
| await clerkClient.users.deleteUser(userId) | ||
|
|
||
| res.status(200).json({ success: true }) | ||
| }) | ||
| ``` | ||
| </Tab> | ||
|
|
||
| <Tab> | ||
| ```tsx {{ filename: 'app/routes/example.tsx' }} | ||
| import { clerkClient, getAuth } from '@clerk/react-router/server' | ||
| import type { Route } from './+types/example' | ||
|
|
||
| export async function loader(args: Route.LoaderArgs) { | ||
| const { userId } = await getAuth(args) | ||
|
|
||
| await clerkClient.users.deleteUser(userId) | ||
|
|
||
| return { success: true } | ||
| } | ||
| ``` | ||
| </Tab> | ||
|
|
||
| <Tab> | ||
| ```tsx {{ filename: 'app/routes/api/example.tsx' }} | ||
| import { json } from '@tanstack/react-start' | ||
| import { createFileRoute } from '@tanstack/react-router' | ||
| import { auth, clerkClient } from '@clerk/tanstack-react-start/server' | ||
|
|
||
| export const ServerRoute = createFileRoute('/api/example')({ | ||
| server: { | ||
| handlers: { | ||
| GET: async () => { | ||
| const { userId } = await auth() | ||
|
|
||
| await clerkClient().users.deleteUser(userId) | ||
|
|
||
| return json({ success: true }) | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| ``` | ||
| </Tab> | ||
| </Tabs> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same "link as comment" note as above.