Skip to content

Commit cec9255

Browse files
committed
docs suggestions
1 parent 9d33494 commit cec9255

File tree

6 files changed

+60
-51
lines changed

6 files changed

+60
-51
lines changed

docs/_partials/create-invitation.mdx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,21 @@
7070
```tsx {{ filename: 'app/routes/example.tsx' }}
7171
import { clerkClient } from '@clerk/react-router/server'
7272
import type { Route } from './+types/example'
73+
import { json } from 'react-router-dom'
74+
75+
export async function action({ request }: Route.ActionArgs) {
76+
const formData = await request.formData()
77+
const emailAddress = formData.get('emailAddress')
78+
const redirectUrl = formData.get('redirectUrl')
79+
const publicMetadata = formData.get('publicMetadata')
7380

74-
export async function loader(args: Route.LoaderArgs) {
7581
await clerkClient.invitations.createInvitation({
76-
emailAddress: 'invite@example.com',
77-
redirectUrl: 'https://www.example.com/my-sign-up',
78-
publicMetadata: {
79-
example: 'metadata',
80-
example_nested: {
81-
nested: 'metadata',
82-
},
83-
},
82+
emailAddress: emailAddress,
83+
redirectUrl: redirectUrl,
84+
publicMetadata: publicMetadata,
8485
})
8586

86-
return { success: true }
87+
return json({ success: true })
8788
}
8889
```
8990
</Tab>

docs/_partials/create-user.mdx

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@
44
import { auth, clerkClient } from '@clerk/nextjs/server'
55
import { NextResponse } from 'next/server'
66

7-
export async function GET() {
8-
try {
9-
const client = await clerkClient()
10-
const user = await client.users.createUser({
11-
emailAddress: ['test@example.com'],
12-
password: 'password',
13-
})
14-
return NextResponse.json({ message: 'User created', user })
15-
} catch (error) {
16-
console.log(error)
17-
return NextResponse.json({ error: 'Error creating user' })
18-
}
7+
export async function POST() {
8+
const client = await clerkClient()
9+
const user = await client.users.createUser({
10+
emailAddress: ['test@example.com'],
11+
password: 'password',
12+
})
13+
14+
return NextResponse.json({ message: 'User created', user })
1915
}
2016
```
2117
</Tab>
@@ -25,7 +21,7 @@
2521
import type { APIRoute } from 'astro'
2622
import { clerkClient } from '@clerk/astro/server'
2723

28-
export const GET: APIRoute = async (context) => {
24+
export const POST: APIRoute = async (context) => {
2925
await clerkClient(context).users.createUser({
3026
emailAddress: ['test@example.com'],
3127
password: 'password',
@@ -53,16 +49,21 @@
5349

5450
<Tab>
5551
```tsx {{ filename: 'app/routes/example.tsx' }}
56-
import { clerkClient, getAuth } from '@clerk/react-router/server'
52+
import { clerkClient } from '@clerk/react-router/server'
5753
import type { Route } from './+types/example'
54+
import { json } from 'react-router-dom'
55+
56+
export async function action({ request }: Route.ActionArgs) {
57+
const formData = await request.formData()
58+
const emailAddress = formData.get('emailAddress')
59+
const password = formData.get('password')
5860

59-
export async function loader(args: Route.LoaderArgs) {
6061
await clerkClient.users.createUser({
61-
emailAddress: ['test@example.com'],
62-
password: 'password',
62+
emailAddress: [emailAddress],
63+
password: password,
6364
})
6465

65-
return { success: true }
66+
return json({ success: true })
6667
}
6768
```
6869
</Tab>
@@ -76,7 +77,7 @@
7677
export const ServerRoute = createFileRoute('/api/example')({
7778
server: {
7879
handlers: {
79-
GET: async () => {
80+
POST: async () => {
8081
await clerkClient().users.createUser({
8182
emailAddress: ['test@example.com'],
8283
password: 'my-secure-password',

docs/_partials/delete-user.mdx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@
4141
```tsx {{ filename: 'app/routes/example.tsx' }}
4242
import { clerkClient } from '@clerk/react-router/server'
4343
import type { Route } from './+types/example'
44+
import { json, redirect } from 'react-router-dom'
4445

45-
export async function loader(args: Route.LoaderArgs) {
46-
await clerkClient.users.deleteUser('user_123')
46+
export async function action({ request }: Route.ActionArgs) {
47+
const formData = await request.formData()
48+
const userId = formData.get('userId')
49+
50+
await clerkClient.users.deleteUser(userId)
4751

48-
return { success: true }
52+
return json({ success: true })
4953
}
5054
```
5155
</Tab>

docs/_partials/revoke-invitation.mdx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@
55
import { NextResponse } from 'next/server'
66

77
export async function POST() {
8-
try {
9-
const client = await clerkClient()
10-
const invitation = await client.invitations.revokeInvitation({
11-
invitationId: 'invitation_123',
12-
})
13-
return NextResponse.json({ message: 'Invitation revoked' })
14-
} catch (error) {
15-
console.log(error)
16-
return NextResponse.json({ error: 'Error revoking invitation' })
17-
}
8+
const client = await clerkClient()
9+
const invitation = await client.invitations.revokeInvitation({
10+
invitationId: 'invitation_123',
11+
})
12+
13+
return NextResponse.json({ message: 'Invitation revoked' })
1814
}
1915
```
2016
</Tab>
@@ -52,13 +48,17 @@
5248
```tsx {{ filename: 'app/routes/example.tsx' }}
5349
import { clerkClient } from '@clerk/react-router/server'
5450
import type { Route } from './+types/example'
51+
import { json, redirect } from 'react-router-dom'
52+
53+
export async function action({ request }: Route.ActionArgs) {
54+
const formData = await request.formData()
55+
const invitationId = formData.get('invitationId')
5556

56-
export async function loader(args: Route.LoaderArgs) {
5757
await clerkClient.invitations.revokeInvitation({
58-
invitationId: 'invitation_123',
58+
invitationId: invitationId,
5959
})
6060

61-
return { success: true }
61+
return json({ success: true })
6262
}
6363
```
6464
</Tab>

docs/guides/configure/auth-strategies/social-connections/overview.mdx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ The following example demonstrates how to retrieve the OAuth access token for a
292292

293293
<Tab>
294294
```tsx {{ filename: 'app/routes/notion.tsx' }}
295-
import { redirect } from 'react-router'
296295
import { getAuth } from '@clerk/react-router/ssr.server'
297296
import { createClerkClient } from '@clerk/react-router/api.server'
298297
import type { Route } from './+types/notion'
@@ -305,7 +304,9 @@ The following example demonstrates how to retrieve the OAuth access token for a
305304

306305
// Protect the route from unauthenticated users
307306
if (!isAuthenticated) {
308-
return redirect('/sign-in?redirect_url=' + args.request.url)
307+
return new Response('User not authenticated', {
308+
status: 404,
309+
})
309310
}
310311

311312
const provider = 'notion'
@@ -319,7 +320,9 @@ The following example demonstrates how to retrieve the OAuth access token for a
319320
}).users.getUserOauthAccessToken(userId, provider)
320321
const accessToken = clerkResponse.data[0].token || ''
321322
if (!accessToken) {
322-
return redirect('/sign-in?redirect_url=' + args.request.url)
323+
return new Response('Access token not found', {
324+
status: 401,
325+
})
323326
}
324327

325328
// Fetch the user data from the Notion API
@@ -338,9 +341,7 @@ The following example demonstrates how to retrieve the OAuth access token for a
338341
const notionData = await notionResponse.json()
339342

340343
// Return the Notion data
341-
return {
342-
notionData: JSON.stringify(notionData),
343-
}
344+
return JSON.stringify({ notionData })
344345
}
345346
```
346347
</Tab>

docs/guides/configure/session-tasks.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ The `<RedirectToTasks />` control component redirects users to the appropriate t
9494
9595
```tsx
9696
<>
97+
{/* Until the user completes their session tasks,
98+
Clerk considers them as signed out, by default */}
9799
<SignedOut>
98100
<RedirectToTasks />
99101
</SignedOut>

0 commit comments

Comments
 (0)