mirror of
https://github.com/supabase/supabase.git
synced 2026-07-02 18:34:44 +08:00
* docs: cleanup auth docs * docs: update auth docs * Update spec/supabase_js_v2_legacy.yml Co-authored-by: dng <danny@supabase.io> * Update spec/supabase_js_v2_legacy.yml Co-authored-by: dng <danny@supabase.io> * Update spec/supabase_js_v2_legacy.yml Co-authored-by: dng <danny@supabase.io> * Update spec/supabase_js_v2_legacy.yml Co-authored-by: dng <danny@supabase.io> * Update spec/supabase_js_v2_legacy.yml Co-authored-by: dng <danny@supabase.io> * Update spec/supabase_js_v2_legacy.yml Co-authored-by: dng <danny@supabase.io> * Update spec/supabase_js_v2_legacy.yml Co-authored-by: dng <danny@supabase.io> * Update spec/supabase_js_v2_legacy.yml Co-authored-by: dng <danny@supabase.io> * Update spec/supabase_js_v2_legacy.yml Co-authored-by: dng <danny@supabase.io> * Update spec/supabase_js_v2_legacy.yml Co-authored-by: dng <danny@supabase.io> * Update spec/supabase_js_v2_legacy.yml Co-authored-by: dng <danny@supabase.io> * Update spec/supabase_js_v2_legacy.yml * update auth docs * add supabase auth admin api overview page * resolve PR comments * resolve PR comments * update auth docs with latest tsdocs Co-authored-by: dng <danny@supabase.io>
264 lines
6.1 KiB
Plaintext
264 lines
6.1 KiB
Plaintext
---
|
|
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
|
|
|
|
<ul className="method-list-group">
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
AdminUserAttributes
|
|
</span>
|
|
<span className="method-list-item-label-badge required">
|
|
required
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
<code>object</code>
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
No description provided.
|
|
|
|
</div>
|
|
|
|
<ul className="method-list-group">
|
|
<h5 class="method-list-title method-list-title-isChild expanded">Properties</h5>
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
app_metadata
|
|
</span>
|
|
<span className="method-list-item-label-badge false">
|
|
optional
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
<code>object</code>
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
A custom data object to store the user's application specific metadata. This maps to the `auth.users.app_metadata` column.
|
|
|
|
Only a service role can modify.
|
|
|
|
The `app_metadata` should be a JSON object that includes app-specific info, such as identity providers, roles, and other
|
|
access control information.
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
data
|
|
</span>
|
|
<span className="method-list-item-label-badge false">
|
|
optional
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
<code>object</code>
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
A custom data object to store the user's metadata. This maps to the `auth.users.user_metadata` column.
|
|
|
|
The `data` should be a JSON object that includes user-specific info, such as their first and last name.
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
email
|
|
</span>
|
|
<span className="method-list-item-label-badge false">
|
|
optional
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
<code>string</code>
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
The user's email.
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
email_confirm
|
|
</span>
|
|
<span className="method-list-item-label-badge false">
|
|
optional
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
<code>boolean</code>
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
Confirms the user's email address if set to true.
|
|
|
|
Only a service role can modify.
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
password
|
|
</span>
|
|
<span className="method-list-item-label-badge false">
|
|
optional
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
<code>string</code>
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
The user's password.
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
phone
|
|
</span>
|
|
<span className="method-list-item-label-badge false">
|
|
optional
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
<code>string</code>
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
The user's phone.
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
phone_confirm
|
|
</span>
|
|
<span className="method-list-item-label-badge false">
|
|
optional
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
<code>boolean</code>
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
Confirms the user's phone number if set to true.
|
|
|
|
Only a service role can modify.
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
user_metadata
|
|
</span>
|
|
<span className="method-list-item-label-badge false">
|
|
optional
|
|
</span>
|
|
<span className="method-list-item-validation">
|
|
<code>object</code>
|
|
</span>
|
|
</h4>
|
|
<div class="method-list-item-description">
|
|
|
|
A custom data object to store the user's metadata. This maps to the `auth.users.user_metadata` column.
|
|
|
|
Only a service role can modify.
|
|
|
|
The `user_metadata` should be a JSON object that includes user-specific info, such as their first and last name.
|
|
|
|
Note: When using the GoTrueAdminApi and wanting to modify a user's metadata,
|
|
this attribute is used instead of UserAttributes data.
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
## Notes
|
|
|
|
- To confirm the user's email address or phone number, set `email_confirm` or `phone_confirm` to true. Both arguments default to false.
|
|
|
|
## Examples
|
|
|
|
### Create a new user with custom user metadata
|
|
|
|
```js
|
|
const { data, error } = await supabase.auth.admin.createUser({
|
|
email: 'user@email.com',
|
|
password: 'password',
|
|
user_metadata: { name: 'Yoda' },
|
|
})
|
|
```
|
|
|
|
### Auto-confirm the user's email
|
|
|
|
```js
|
|
const { data, error } = await supabase.auth.admin.createUser({
|
|
email: 'user@email.com',
|
|
email_confirm: true,
|
|
})
|
|
```
|
|
|
|
### Auto-confirm the user's phone number
|
|
|
|
```js
|
|
const { data, error } = await supabase.auth.admin.createUser({
|
|
phone: '1234567890',
|
|
phone_confirm: true,
|
|
})
|
|
```
|