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. In the top in the Clerk Dashboard, select Users.
  2. Select Create user.
  3. 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 client = await clerkClient()

    const user = await client.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' })
  }
}

Caution

On January 8, 2025, the Node SDK will no longer be available. Upgrade to the Express SDK.

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