Skip to content

Commit 160f432

Browse files
authored
Audit /users docs; lint /using-proxies (#2079)
1 parent 0c5bfde commit 160f432

File tree

9 files changed

+173
-182
lines changed

9 files changed

+173
-182
lines changed

docs/_partials/user-object.mdx

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The `User` object holds all of the information for a single user of your application and provides a set of methods to manage their account. Each `User` has at least one authentication [identifier](/docs/authentication/configuration/sign-up-sign-in-options#identifiers), which might be their email address, phone number, or a username.
2+
3+
A user can be contacted at their primary email address or primary phone number. They can have more than one registered email address, but only one of them will be their primary email address. This goes for phone numbers as well; a user can have more than one, but only one phone number will be their primary. At the same time, a user can also have one or more external accounts by connecting to [social providers](/docs/authentication/social-connections/overview) such as Google, Apple, Facebook, and many more.
4+
5+
Finally, a `User` object holds profile data like the user's name, profile picture, and a set of [metadata](/docs/users/metadata) that can be used internally to store arbitrary information. The metadata are split into `publicMetadata` and `privateMetadata`. Both types are set from the [Backend API](/docs/reference/backend-api){{ target: '_blank' }}, but public metadata can also be accessed from the [Frontend API](/docs/reference/frontend-api){{ target: '_blank' }}.

docs/advanced-usage/using-proxies.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ When using a proxy, all requests to the Frontend API will be made through your d
122122

123123
const proxyUrl = new URL(request.url)
124124
proxyUrl.host = 'frontend-api.clerk.dev'
125-
proxyUrl.port = "443"
125+
proxyUrl.port = '443'
126126
proxyUrl.protocol = 'https'
127127
proxyUrl.pathname = proxyUrl.pathname.replace('/__clerk', '')
128128

docs/references/javascript/user.mdx

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ title: '`User` object'
33
description: The User object holds all the information for a user of your application and provides a set of methods to manage their account. Users have a unique authentication identifier which might be their email address, phone number or a username.
44
---
55

6-
The `User` object holds all of the information for a single user of your application and provides a set of methods to manage their account. Each user has a unique authentication identifier which might be their email address, phone number, or a username.
7-
8-
A user can be contacted at their primary email address or primary phone number. They can have more than one registered email address, but only one of them will be their primary email address. This goes for phone numbers as well; a user can have more than one, but only one phone number will be their primary. At the same time, a user can also have one or more external accounts by connecting to [social providers](/docs/authentication/social-connections/overview) such as Google, Apple, Facebook, and many more.
9-
10-
Finally, a `User` object holds profile data like the user's name, profile picture, and a set of [metadata](/docs/users/metadata) that can be used internally to store arbitrary information. The metadata are split into `publicMetadata` and `privateMetadata`. Both types are set from the [Backend API](/docs/reference/backend-api){{ target: '_blank' }}, but public metadata can also be accessed from the [Frontend API](/docs/reference/frontend-api){{ target: '_blank' }}.
6+
<Include src="_partials/user-object" />
117

128
The ClerkJS SDK provides some helper [methods](#methods) on the `User` object to help retrieve and update user information and authentication status.
139

docs/users/creating-users.mdx

+26-13
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,54 @@ title: Create users
33
description: Learn how to create users in your Clerk application.
44
---
55

6-
There are two ways to create users in Clerk: [through the Clerk Dashboard](#create-users-in-the-clerk-dashboard) or [using the Clerk API](#create-users-using-the-clerk-api).
6+
There are two ways to create users in Clerk: [in the Clerk Dashboard](#in-the-clerk-dashboard) or [using the Backend API](#using-the-backend-api).
77

8-
## Create users in the Clerk Dashboard
8+
## In the Clerk Dashboard
99

1010
To create users in the Clerk Dashboard:
1111

1212
1. In the top in the Clerk Dashboard, select [**Users**](https://dashboard.clerk.com/last-active?path=users).
1313
1. Select **Create user**.
1414
1. Enter the required user details and select **Create**.
1515

16-
## Create users using the Clerk API
16+
## Using the Backend API
1717

18-
To create users using the Clerk API, you can use the [`createUser()`](/docs/references/backend/user/create-user) method from the `users` sub-api of the `clerkClient` instance.
18+
You can create users in your app using Clerk's Backend API.
1919

20-
<Tabs items={["Next.js", "Express", "cURL"]}>
20+
Use the following tabs to see examples of how to create users using one of the following:
21+
22+
- Frontend SDKs, such as Next.js, React, or Remix
23+
- Express
24+
- cURL
25+
26+
<Tabs items={["Fullstack SDKs", "Express", "cURL"]}>
2127
<Tab>
22-
```ts {{ filename: 'app/api/create-user/route.ts' }}
23-
import { clerkClient } from '@clerk/nextjs/server'
24-
import { NextResponse } from 'next/server'
28+
The following example shows how to create a user using the JavaScript Backend SDK's [`createUser()`](/docs/references/backend/user/create-user) method from the `users` sub-api of the `clerkClient` instance.
2529

30+
```ts {{ filename: 'route.ts' }}
2631
export async function POST() {
2732
try {
28-
const client = await clerkClient()
29-
30-
const user = await client.users.createUser({
33+
const user = await clerkClient.users.createUser({
3134
emailAddress: ['[email protected]'],
3235
password: 'password',
3336
})
34-
return NextResponse.json({ message: 'User created', user })
37+
return Response.json({ message: 'User created', user })
3538
} catch (error) {
3639
console.log(error)
37-
return NextResponse.json({ error: 'Error creating user' })
40+
return Response.json({ error: 'Error creating user' })
3841
}
3942
}
4043
```
44+
45+
<If sdk="nextjs">
46+
If you're using Next.js, you must `await` the instantiation of the `clerkClient` instance, like so:
47+
48+
```ts
49+
const client = await clerkClient()
50+
51+
const response = await client.users.createUser()
52+
```
53+
</If>
4154
</Tab>
4255

4356
<Tab>

docs/users/deleting-users.mdx

+26-12
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,52 @@ title: Delete users
33
description: Learn how to delete users in your Clerk application.
44
---
55

6-
There are two ways to delete users in Clerk: [through the Clerk Dashboard](#delete-users-in-the-clerk-dashboard) or [using the Clerk API](#delete-users-using-the-clerk-api).
6+
There are two ways to delete users in Clerk: [in the Clerk Dashboard](#in-the-clerk-dashboard) or [using the Backend API](#using-the-backend-api).
77

8-
## Delete users in the Clerk Dashboard
8+
## In the Clerk Dashboard
99

1010
To delete users in the Clerk Dashboard:
1111

1212
1. At the top of the Clerk Dashboard, select [**Users**](https://dashboard.clerk.com/last-active?path=users).
1313
1. You can either select the user and then in the side navigation menu, select **Delete user**, or select the menu icon on the right side of the user's row and select **Delete user**.
1414

15-
## Delete users using the Clerk API
15+
## Using the Backend API
1616

17-
To delete users using the Clerk API, you can use the [`deleteUser()`](/docs/references/backend/user/delete-user) method from the `users` sub-api of the `clerkClient` instance.
17+
You can delete users in your app using Clerk's Backend API.
1818

19-
<Tabs items={["Next.js", "Express", "cURL"]}>
19+
Use the following tabs to see examples of how to delete users using one of the following:
20+
21+
- Frontend SDKs, such as Next.js, React, or Remix
22+
- Express
23+
- cURL
24+
25+
<Tabs items={["Fullstack SDKs", "Express", "cURL"]}>
2026
<Tab>
21-
```ts {{ filename: 'app/api/delete-user/route.ts' }}
22-
import { clerkClient } from '@clerk/nextjs/server'
23-
import { NextResponse } from 'next/server'
27+
The following example shows how to delete a user using the JavaScript Backend SDK's [`deleteUser()`](/docs/references/backend/user/delete-user) method from the `users` sub-api of the `clerkClient` instance.
2428

29+
```ts {{ filename: 'route.ts' }}
2530
export async function DELETE() {
2631
const userId = 'user_123'
2732

2833
try {
29-
const client = await clerkClient()
30-
await client.users.deleteUser(userId)
31-
return NextResponse.json({ message: 'User deleted' })
34+
await clerkClient.users.deleteUser(userId)
35+
return Response.json({ message: 'User deleted' })
3236
} catch (error) {
3337
console.log(error)
34-
return NextResponse.json({ error: 'Error deleting user' })
38+
return Response.json({ error: 'Error deleting user' })
3539
}
3640
}
3741
```
42+
43+
<If sdk="nextjs">
44+
If you're using Next.js, you must `await` the instantiation of the `clerkClient` instance, like so:
45+
46+
```ts
47+
const client = await clerkClient()
48+
49+
const response = await client.users.deleteUser(userId)
50+
```
51+
</If>
3852
</Tab>
3953

4054
<Tab>

docs/users/invitations.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ curl https://api.clerk.com/v1/invitations -X POST -d '{"email_address": "email@e
9090

9191
## Revoking invitations
9292

93-
You can revoke an invitation at any time. Revoking an invitation prevents the user from using the invitation link that was sent to them.
93+
You can revoke an invitation at any time. Revoking an invitation prevents the user from using the invitation link that was sent to them. You can revoke an invitation in the [Clerk Dashboard](#using-clerk-dashboard-2) or [using the Backend API](#using-backend-api-2).
9494

9595
### Using Clerk Dashboard
9696

@@ -101,7 +101,7 @@ To revoke an invitation, navigate to the **Users** page from the top-level menu,
101101
102102
### Using Backend API
103103

104-
You can either use a cURL command or the [JavaScript Backend SDK](/docs/references/backend/overview) to create an invitation. Use the following tabs to see examples for each method.
104+
You can either use a cURL command or the [JavaScript Backend SDK](/docs/references/backend/overview) to revoke an invitation. Use the following tabs to see examples for each method.
105105

106106
<Tabs items={["cURL", "Backend SDK"]}>
107107
<Tab>
@@ -132,4 +132,4 @@ See the [Backend API reference](/docs/reference/backend-api/tag/Invitations#oper
132132
133133
## Custom flow
134134

135-
Clerk's [prebuilt components](/docs/components/overview) and [Account Portal pages](/docs/account-portal/overview) handle the sign-up flow for you, including the invitation flow. If you want to build a **custom** sign-up flow, see the [custom flow](/docs/custom-flows/application-invitations) guide.
135+
Clerk's [prebuilt components](/docs/components/overview) and [Account Portal pages](/docs/account-portal/overview) handle the sign-up flow for you, including the invitation flow. If Clerk's prebuilt components don't meet your specific needs or if you require more control over the logic, you can rebuild the existing Clerk flows using the Clerk API. For more information, see the [custom flow for application invitations](/docs/custom-flows/application-invitations).

0 commit comments

Comments
 (0)