---
id: auth-admin-createuser
title: 'createUser()'
slug: /auth-admin-createuser
custom_edit_url: https://github.com/supabase/supabase/edit/master/spec/supabase_js_v2_legacy.yml
---
import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'
Creates a new user.
This function should only be called on a server. Never expose your `service_role` key in the browser.
```js
const { data, error } = await supabase.auth.admin.createUser({
email: 'user@email.com',
password: 'password',
user_metadata: { name: 'Yoda' },
})
```
## Parameters
-
AdminUserAttributes
required
object
No description provided.
Properties
-
app_metadata
optional
object
A custom data object for app_metadata that.
Only a service role can modify.
Can be any JSON that includes app-specific info, such as identity providers, roles, and other
access control information.
-
data
optional
object
A custom data object for user_metadata that a user can modify. Can be any JSON.
-
email
optional
string
The user's email.
-
email_change_token
optional
string
An email change token.
-
email_confirm
optional
boolean
Sets if a user has confirmed their email address.
Only a service role can modify.
-
password
optional
string
The user's password.
-
phone
optional
string
The user's phone.
-
phone_confirm
optional
boolean
Sets if a user has confirmed their phone number.
Only a service role can modify.
-
user_metadata
optional
object
A custom data object for user_metadata.
Can be any JSON.
Only a service role can modify.
Note: When using the GoTrueAdminApi and wanting to modify a user's user_metadata,
this attribute is used instead of UserAttributes data.
## Notes
- Requires a `service_role` key.
- This function should be called on a server. Never expose your `service_role` key in the browser.
- If you do not provide the `email_confirm` and `phone_confirm` options to this function, both will default to false.
## Examples
### Create a new user.
```js
const { data, error } = await supabase.auth.admin.createUser({
email: 'user@email.com',
password: 'password',
user_metadata: { name: 'Yoda' },
})
```
### Auto-confirm email.
```js
const { data, error } = await supabase.auth.admin.createUser({
email: 'user@email.com',
email_confirm: true,
})
```
### Auto-confirm phone.
```js
const { data, error } = await supabase.auth.admin.createUser({
phone: '1234567890',
phone_confirm: true,
})
```