1 | |
2 | type Clerk = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Create a new user |
7 | * Creates a new user. Your user management settings determine how you should setup your user model. |
8 |
|
9 | Any email address and phone number created using this method will be marked as verified. |
10 |
|
11 | Note: If you are performing a migration, check out our guide on [zero downtime migrations](https://clerk.com/docs/deployments/migrate-overview). |
12 |
|
13 | A rate limit rule of 20 requests per 10 seconds is applied to this endpoint. |
14 | */ |
15 | export async function main( |
16 | auth: Clerk, |
17 | body: { |
18 | external_id?: string; |
19 | first_name?: string; |
20 | last_name?: string; |
21 | email_address?: string[]; |
22 | phone_number?: string[]; |
23 | web3_wallet?: string[]; |
24 | username?: string; |
25 | password?: string; |
26 | password_digest?: string; |
27 | password_hasher?: string; |
28 | skip_password_checks?: false | true; |
29 | skip_password_requirement?: false | true; |
30 | totp_secret?: string; |
31 | backup_codes?: string[]; |
32 | public_metadata?: {}; |
33 | private_metadata?: {}; |
34 | unsafe_metadata?: {}; |
35 | delete_self_enabled?: false | true; |
36 | legal_accepted_at?: string; |
37 | skip_legal_checks?: false | true; |
38 | create_organization_enabled?: false | true; |
39 | create_organizations_limit?: number; |
40 | created_at?: string; |
41 | }, |
42 | ) { |
43 | const url = new URL(`https://api.clerk.com/v1/users`); |
44 |
|
45 | const response = await fetch(url, { |
46 | method: "POST", |
47 | headers: { |
48 | "Content-Type": "application/json", |
49 | Authorization: "Bearer " + auth.apiKey, |
50 | }, |
51 | body: JSON.stringify(body), |
52 | }); |
53 | if (!response.ok) { |
54 | const text = await response.text(); |
55 | throw new Error(`${response.status} ${text}`); |
56 | } |
57 | return await response.json(); |
58 | } |
59 |
|