mirror of
https://github.com/supabase/supabase.git
synced 2026-10-13 13:19:09 +03:00
165 lines
3.7 KiB
Plaintext
165 lines
3.7 KiB
Plaintext
---
|
|
id: auth-updateuser
|
|
title: 'updateUser()'
|
|
slug: /auth-updateuser
|
|
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'
|
|
|
|
Updates user data, if there is a logged in user.
|
|
|
|
```js
|
|
const { data, error } = await supabase.auth.updateUser({
|
|
data: { hello: 'world' },
|
|
})
|
|
```
|
|
|
|
## Parameters
|
|
|
|
<ul className="method-list-group">
|
|
|
|
<li className="method-list-item">
|
|
<h4 className="method-list-item-label">
|
|
<span className="method-list-item-label-name">
|
|
UserAttributes
|
|
</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">
|
|
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">
|
|
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>
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
## Notes
|
|
|
|
- In order to use the `updateUser()` method, the user needs to be signed in first.
|
|
- By Default, email updates sends a confirmation link to both the user's current and new email.
|
|
To only send a confirmation link to the user's new email, disable **Secure email change** in your project's [email auth provider settings](https://app.supabase.com/project/_/auth/settings).
|
|
|
|
## Examples
|
|
|
|
### Update the email for an authenticated user
|
|
|
|
Sends a "Confirm Email Change" email to the new email address.
|
|
|
|
```js
|
|
const { data, error } = await supabase.auth.updateUser({
|
|
email: 'new@email.com',
|
|
})
|
|
```
|
|
|
|
### Update the password for an authenticated user
|
|
|
|
```js
|
|
const { data, error } = await supabase.auth.updateUser({
|
|
password: 'new password',
|
|
})
|
|
```
|
|
|
|
### Update the user's metadata
|
|
|
|
```js
|
|
const { data, error } = await supabase.auth.updateUser({
|
|
data: { hello: 'world' },
|
|
})
|
|
```
|