Create users
There are two ways to create users in Clerk: in the Clerk Dashboard or using the Backend API.
In the Clerk Dashboard
To create users in the Clerk Dashboard:
- In the top in the Clerk Dashboard, select Users.
- Select Create user.
- Enter the required user details and select Create.
Using the Backend API
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:
- Frontend SDKs, such as Next.js, React, or Remix
- Express
- cURL
The following example shows how to create a user using the JavaScript Backend SDK's createUser()
method from the users
sub-api of the clerkClient
instance.
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 you're using Next.js, you must await
the instantiation of the clerkClient
instance, like so:
const client = await clerkClient()
const response = await client.users.createUser()
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' })
}
})
curl 'https://api.clerk.com/v1/users' -X POST -H 'Authorization:Bearer YOUR_SECRET_KEY' -H 'Content-Type:application/json' -d '{
"email_address": ["test@example.com"],
"password": "my-secure-password"
}'
Feedback
Last updated on