|
4 | 4 | import { auth, clerkClient } from '@clerk/nextjs/server' |
5 | 5 | import { NextResponse } from 'next/server' |
6 | 6 |
|
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 }) |
19 | 15 | } |
20 | 16 | ``` |
21 | 17 | </Tab> |
|
25 | 21 | import type { APIRoute } from 'astro' |
26 | 22 | import { clerkClient } from '@clerk/astro/server' |
27 | 23 |
|
28 | | - export const GET: APIRoute = async (context) => { |
| 24 | + export const POST: APIRoute = async (context) => { |
29 | 25 | await clerkClient(context).users.createUser({ |
30 | 26 | emailAddress: ['test@example.com'], |
31 | 27 | password: 'password', |
|
53 | 49 |
|
54 | 50 | <Tab> |
55 | 51 | ```tsx {{ filename: 'app/routes/example.tsx' }} |
56 | | - import { clerkClient, getAuth } from '@clerk/react-router/server' |
| 52 | + import { clerkClient } from '@clerk/react-router/server' |
57 | 53 | 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') |
58 | 60 |
|
59 | | - export async function loader(args: Route.LoaderArgs) { |
60 | 61 | await clerkClient.users.createUser({ |
61 | | - emailAddress: ['test@example.com'], |
62 | | - password: 'password', |
| 62 | + emailAddress: [emailAddress], |
| 63 | + password: password, |
63 | 64 | }) |
64 | 65 |
|
65 | | - return { success: true } |
| 66 | + return json({ success: true }) |
66 | 67 | } |
67 | 68 | ``` |
68 | 69 | </Tab> |
|
76 | 77 | export const ServerRoute = createFileRoute('/api/example')({ |
77 | 78 | server: { |
78 | 79 | handlers: { |
79 | | - GET: async () => { |
| 80 | + POST: async () => { |
80 | 81 | await clerkClient().users.createUser({ |
81 | 82 | emailAddress: ['test@example.com'], |
82 | 83 | password: 'my-secure-password', |
|
0 commit comments