Docs

Create users

There are two ways to create users in Clerk: through the Clerk Dashboard or using the Clerk API.

Create users in the Clerk Dashboard

To create users in the Clerk Dashboard:

  1. Navigate to the Clerk Dashboard.
  2. In the top navigation, select Users.
  3. Select Create user at the top right of the page.
  4. Enter the required user details and select Create.

Create users using the Clerk API

To create users using the Clerk API, you can use the createUser() method from the users sub-api of the clerkClient instance.

app/api/create-user/route.ts
import { clerkClient } from '@clerk/nextjs/server'
import { NextResponse } from 'next/server'

export async function POST() {
  try {
    const user = await clerkClient.users.createUser({
      emailAddress: ['test@example.com'],
      password: 'password',
    })
    return NextResponse.json({ message: 'User created', user })
  } catch (error) {
    console.log(error)
    return NextResponse.json({ error: 'Error creating user' })
  }
}
create-user.ts
import { clerkClient } from '@clerk/clerk-sdk-node'

app.post('/createUser', async (req, res) => {
  const userData = req.body

  try {
    const user = await clerkClient.users.createUser(userData)
    return res.status(200).json({ message: 'User created', user })
  } catch (error) {
    console.log(error)
    return res.status(500).json({ error: 'Error creating user' })
  }
})
terminal
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

What did you think of this content?

Last updated on