Files
supabase/apps/reference/_supabase_js_versioned_docs/version-v1/auth-api-createuser.mdx
2022-08-03 21:03:58 +02:00

148 lines
2.4 KiB
Plaintext

---
id: auth-api-createuser
title: "createUser()"
slug: auth-api-createuser
custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/supabase.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.
<Tabs
defaultValue="js"
groupId="reference/supabase-js"
values={[{ label: 'JavaScript', value: 'js' }]}>
<TabItem value="js">
```js
const { data: user, error } = await supabase.auth.api.createUser({
email: 'user@email.com',
password: 'password',
user_metadata: { name: 'Yoda' }
})
```
</TabItem>
</Tabs>
## Parameters
<ul className="method-list-group">
<li className="method-list-item">
<h4 className="method-list-item-label">
<span className="method-list-item-label-name">
attributes
</span>
<span className="method-list-item-label-badge required">
required
</span>
<span className="method-list-item-validation">
<code>AdminUserAttributes</code>
</span>
</h4>
<div class="method-list-item-description">
The data you want to create the user with.
</div>
</li>
</ul>
## 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.
<Tabs
defaultValue="js"
groupId="reference/supabase-js"
values={[{ label: 'JavaScript', value: 'js' }]}>
<TabItem value="js">
```js
const { data: user, error } = await supabase.auth.api.createUser({
email: 'user@email.com',
password: 'password',
user_metadata: { name: 'Yoda' }
})
```
</TabItem>
</Tabs>
### Auto-confirm email.
<Tabs
defaultValue="js"
groupId="reference/supabase-js"
values={[{ label: 'JavaScript', value: 'js' }]}>
<TabItem value="js">
```js
const { data: user, error } = await supabase.auth.api.createUser({
email: 'user@email.com',
email_confirm: true
})
```
</TabItem>
</Tabs>
### Auto-confirm phone.
<Tabs
defaultValue="js"
groupId="reference/supabase-js"
values={[{ label: 'JavaScript', value: 'js' }]}>
<TabItem value="js">
```js
const { data: user, error } = await supabase.auth.api.createUser({
phone: '1234567890',
phone_confirm: true
})
```
</TabItem>
</Tabs>