āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā š shadcn/directory/clerk/clerk-docs/guides/users/managing ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
To get started, it's important to first understand Clerk's User object.
For more information on the User object, such as helper methods for retrieving and updating user information and authentication status, see the reference docs. The User object is also available in the backend, but it looks slightly different. For more information, see the Backend User object reference docs.
You can manage your users in the Clerk Dashboard, or in your app.
To manage users in the Clerk Dashboard, navigate to the Users page.
You can manage users in your app either through the frontend or backend.
Depending on the level of abstraction you need, you can manage users in the frontend using Clerk's prebuilt components, React hooks, or lower-level JavaScript methods.
<UserButton /> and <UserProfile /> to help your users manage their profile data.User object and helpful methods for managing user authentication and profile data.The JS Backend SDK exposes the Backend API{{ target: '_blank' }} resources and low-level authentication utilities for JavaScript environments.
There are many operations available for managing users, such as getUser(), createUser(), and deleteUser(). For more information, see the JS Backend reference docs.
There are two ways to create users in Clerk: in the Clerk Dashboard or using the Backend API.
To create users in the Clerk Dashboard:
You can create users in your app using Clerk's Backend API.
Use the following tabs to see examples of how to create users using one of the following:
<Tabs items={["JS Backend SDK", "Express", "cURL"]}>
<Tab>
The following example shows how to create a user using the JS Backend SDK's createUser() method from the users sub-api of the clerkClient instance.
<Include src="_partials/backend/usage" />
```ts {{ filename: 'route.ts' }}
export async function POST() {
try {
const user = await clerkClient.users.createUser({
emailAddress: ['test@example.com'],
password: 'password',
})
return Response.json({ message: 'User created', user })
} catch (error) {
console.log(error)
return Response.json({ error: 'Error creating user' })
}
}
```
<If sdk="nextjs">
If you're using Next.js, you must `await` the instantiation of the `clerkClient` instance, like so:
```ts
const client = await clerkClient()
const response = await client.users.createUser()
```
</If>
</Tab>
<Tab>
```ts {{ filename: 'create-user.ts' }}
import { clerkClient } from '@clerk/express'
app.post('/createUser', async (req, res) => {
const userData = req.body
try {
const user = await clerkClient.users.createUser(userData)
res.status(200).json({ message: 'User created', user })
} catch (error) {
console.log(error)
res.status(500).json({ error: 'Error creating user' })
}
})
```
</Tab>
<Tab>
```bash {{ filename: 'terminal' }}
curl 'https://api.clerk.com/v1/users' -X POST -H 'Authorization:Bearer {{secret}}' -H 'Content-Type:application/json' -d '{
"email_address": ["test@example.com"],
"password": "my-secure-password"
}'
```
</Tab>
</Tabs>
There are two ways to delete users in Clerk: in the Clerk Dashboard or using the Backend API.
To delete users in the Clerk Dashboard:
You can delete users in your app using Clerk's Backend API.
Use the following tabs to see examples of how to delete users using one of the following:
<Tabs items={["JS Backend SDK", "Express", "cURL"]}>
<Tab>
The following example shows how to delete a user using the JS Backend SDK's deleteUser() method from the users sub-api of the clerkClient instance.
<Include src="_partials/backend/usage" />
```ts {{ filename: 'route.ts' }}
export async function DELETE() {
const userId = 'user_123'
try {
await clerkClient.users.deleteUser(userId)
return Response.json({ message: 'User deleted' })
} catch (error) {
console.log(error)
return Response.json({ error: 'Error deleting user' })
}
}
```
<If sdk="nextjs">
If you're using Next.js, you must `await` the instantiation of the `clerkClient` instance, like so:
```ts
const client = await clerkClient()
const response = await client.users.deleteUser(userId)
```
</If>
</Tab>
<Tab>
```ts {{ filename: 'delete-user.ts' }}
import { clerkClient } from '@clerk/express'
app.post('/deleteUser', async (req, res) => {
const userId = req.body.userId
try {
await clerkClient.users.deleteUser(userId)
res.status(200).json({ message: 'User deleted' })
} catch (error) {
console.log(error)
res.status(500).json({ error: 'Error deleting user' })
}
})
```
</Tab>
<Tab>
```bash {{ filename: 'terminal' }}
curl 'https://api.clerk.com/v1/users/{user_id}' -X DELETE -H 'Authorization:Bearer {{secret}}' -H 'Content-Type:application/json'
```
</Tab>
</Tabs>ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā