Files
supabase/apps/temp-docs/docs/reference/javascript/auth-update.mdx
2022-04-26 14:17:19 +02:00

137 lines
2.5 KiB
Plaintext

---
id: auth-update
title: "update()"
slug: auth-update
custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/supabase.yml
---
import Tabs from '@theme/Tabs';
import TabsPanel from '@theme/TabsPanel';
Updates user data, if there is a logged in user.
<Tabs
defaultActiveId="js"
groupId="reference/supabase-js"
values={[{ label: 'JavaScript', value: 'js' }]}>
<TabsPanel id="js" label="js">
```js
const { user, error } = await supabase.auth.update({email: 'new@email.com'})
```
</TabsPanel>
</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>UserAttributes</code>
</span>
</h4>
<div class="method-list-item-description">
No description provided.
</div>
</li>
</ul>
## Notes
User email: Email updates will send an email to both the user's current and new email with a confirmation link by default.
To toggle this behavior off and only send a single confirmation link to the new email, toggle "Double confirm email changes" under "Authentication" -> "Settings" off.
User metadata: It's generally better to store user data in a table inside your public schema (i.e. `public.users`).
Use the `update()` method if you have data which rarely changes or is specific only to the logged in user.
## Examples
### Update email for authenticated user.
Sends a "Confirm Email Change" email to the new email address.
<Tabs
defaultActiveId="js"
groupId="reference/supabase-js"
values={[{ label: 'JavaScript', value: 'js' }]}>
<TabsPanel id="js" label="js">
```js
const { user, error } = await supabase.auth.update({email: 'new@email.com'})
```
</TabsPanel>
</Tabs>
### Update password for authenticated user.
<Tabs
defaultActiveId="js"
groupId="reference/supabase-js"
values={[{ label: 'JavaScript', value: 'js' }]}>
<TabsPanel id="js" label="js">
```js
const { user, error } = await supabase.auth.update({password: 'new password'})
```
</TabsPanel>
</Tabs>
### Update a user's metadata.
<Tabs
defaultActiveId="js"
groupId="reference/supabase-js"
values={[{ label: 'JavaScript', value: 'js' }]}>
<TabsPanel id="js" label="js">
```js
const { user, error } = await supabase.auth.update({
data: { hello: 'world' }
})
```
</TabsPanel>
</Tabs>