docs: update auth docs

This commit is contained in:
Kang Ming committed 2022-08-16 22:43:05 +08:00
1 parent f9edc841d5
commit 03e4840cba
9 files changed
+233 -18

No files matched your search

@@ -10,6 +10,12 @@ import TabItem from '@theme/TabItem'
Sends an invite link to an email address.
```js
const { data, error } = await supabase.auth.admin.inviteUserByEmail(
'email@example.com'
)
```
## Parameters
<ul className="method-list-group">
@@ -13,7 +13,7 @@ Updates the user data.
```js
const { data: user, error } = await supabase.auth.admin.updateUserById(
'6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4',
{ email: 'new@email.com' }
{ user_metadata: { hello: 'world' } }
)
```
@@ -10,6 +10,12 @@ import TabItem from '@theme/TabItem'
Log in an existing user via a third-party provider.
```js
const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'github',
})
```
## Parameters
<ul className="method-list-group">
@@ -10,6 +10,13 @@ import TabItem from '@theme/TabItem'
Log in an existing user, or login via a third-party provider.
```js
const { data, error } = await supabase.auth.signInWithPassword({
email: 'example@email.com',
password: 'example-password',
})
```
## Parameters
<ul className="method-list-group">
@@ -149,3 +156,33 @@ Verification token received when the user completes the captcha on the site.
## Notes
- Requires either an email and password or a phone number and password.
## Examples
### Sign in with Email.
Sign in with email and password. After a user has verified their email, they can use the [`signInWithPassword()`](/docs/reference/javascript/auth-signin#sign-in-using-phone) method.
```js
const { data, error } = await supabase.auth.signInWithPassword({
email: 'example@email.com',
password: 'example-password',
})
```
### Sign in with Phone.
Supabase supports Phone Auth. After a user has verified their number, they can use the [`signIn()`](/docs/reference/javascript/auth-signin#sign-in-using-phone) method.
```js
const { data, error } = await supabase.auth.signInWithPassword({
phone: '+13334445555',
password: 'some-password',
})
// After receiving an SMS with One Time Password.
let { data, error } = await supabase.auth.verifyOtp({
phone: '+13334445555',
token: '123456',
})
```
@@ -11,8 +11,8 @@ import TabItem from '@theme/TabItem'
Updates user data, if there is a logged in user.
```js
const { data, error } = await supabase.auth.updateUser({
email: 'new@email.com',
const { user, error } = await supabase.auth.updateUser({
data: { hello: 'world' },
})
```
@@ -0,0 +1,136 @@
---
id: auth-verifyotp
title: 'verifyOtp()'
slug: /auth-verifyotp
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'
Log in a user given a User supplied OTP received via mobile.
```js
const { data, error } = await supabase.auth.verifyOtp({
phone,
token,
type: 'sms',
})
```
## Parameters
<ul className="method-list-group">
<li className="method-list-item">
<h4 className="method-list-item-label">
<span className="method-list-item-label-name">
VerifyOtpParams
</span>
<span className="method-list-item-label-badge required">
required
</span>
<span className="method-list-item-validation">
<code>VerifyMobileOtpParams</code> | <code>VerifyEmailOtpParams</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>
</ul>
</li>
<li className="method-list-item">
<h4 className="method-list-item-label">
<span className="method-list-item-label-name">
options
</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">
captchaToken
</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">
Verification token received when the user completes the captcha on the site.
</div>
</li>
<li className="method-list-item">
<h4 className="method-list-item-label">
<span className="method-list-item-label-name">
redirectTo
</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">
A URL to send the user to after they are confirmed.
</div>
</li>
</ul>
</li>
</ul>
## Examples
### Verify Sms Otp
```js
const { data, error } = await supabase.auth.verifyOtp({
phone,
token,
type: 'sms',
})
```
### Verify Signup Otp
```js
const { data, error } = await supabase.auth.verifyOtp({
email,
token,
type: 'signup',
})
```
@@ -38,6 +38,7 @@ const sidebars = {
'generated/auth-signinwithotp',
'generated/auth-signinwithoauth',
'generated/auth-signout',
'generated/auth-verifyotp',
'generated/auth-getsession',
'generated/auth-getuser',
'generated/auth-updateuser',
+10
View File
@@ -372,6 +372,11 @@ module.exports = withMDX({
source: '/docs/client/auth-signout',
destination: '/docs/reference/javascript/auth-signout',
},
{
permanent: false,
source: '/docs/client/auth-verifyotp',
destination: '/docs/reference/javascript/auth-verifyotp',
},
{
permanent: false,
source: '/docs/client/auth-session',
@@ -1431,6 +1436,11 @@ module.exports = withMDX({
// },
// {
// permanent: true,
// source: '/docs/reference/javascript/auth-api-verifyotp',
// destination: '/docs/reference/javascript/auth-verifyotp',
// },
// {
// permanent: true,
// source: '/docs/reference/javascript/auth-api-listusers',
// destination: '/docs/reference/javascript/auth-admin-listusers',
// },
+34 -15
View File
@@ -39,7 +39,7 @@ pages:
})
```
- name: Sign up with additional user meta data.
isSpotlight: true
isSpotlight: false
js: |
```js
const { data, error } = await supabase.auth.signUp(
@@ -60,8 +60,9 @@ pages:
$ref: '@supabase/gotrue-js.GoTrueClient.signInWithPassword'
notes: |
- Requires either an email and password or a phone number and password.
example:
examples:
- name: Sign in with Email.
isSpotlight: true
description: |
Sign in with email and password. After a user has verified their email, they can use the [`signInWithPassword()`](/docs/reference/javascript/auth-signin#sign-in-using-phone) method.
js: |
@@ -72,6 +73,7 @@ pages:
})
```
- name: Sign in with Phone.
isSpotlight: false
description: |
Supabase supports Phone Auth. After a user has verified their number, they can use the [`signIn()`](/docs/reference/javascript/auth-signin#sign-in-using-phone) method.
js: |
@@ -107,7 +109,7 @@ pages:
})
```
- name: Sign in with sms otp.
isSpotlight: true
isSpotlight: false
description: The user will be sent an otp to their phone number. By default, a given user can only request an otp once every 60 seconds.
js: |
```js
@@ -123,6 +125,7 @@ pages:
- Supabase supports many different [third-party providers](https://supabase.com/docs/guides/auth#providers).
examples:
- name: Sign in using a third-party provider.
isSpotlight: true
js: |
```js
const { data, error } = await supabase.auth.signInWithOAuth({
@@ -130,6 +133,7 @@ pages:
})
```
- name: Sign in using a third-party provider with redirect.
isSpotlight: false
description: |
The `redirectTo` param will only applied on the callback made from the third-party provider. It does not redirect the user immediately after invoking this method.
In order for the `redirectTo` param to be allowed, one needs to include it in an allowlist. Supabase supports this for
@@ -144,6 +148,7 @@ pages:
}
```
- name: Sign in with scopes.
isSpotlight: false
description: |
If you need additional data from an OAuth provider, you can include a space-separated list of scopes in your request to get back an OAuth provider token.
You may also need to specify the scopes in the provider's OAuth app settings, depending on the provider.
@@ -167,6 +172,22 @@ pages:
```js
const { error } = await supabase.auth.signOut()
```
auth.verifyOtp():
title: 'verifyOtp()'
$ref: '@supabase/gotrue-js.GoTrueClient.verifyOtp'
examples:
- name: Verify Sms Otp
isSpotlight: true
js: |
```js
const { data, error } = await supabase.auth.verifyOtp({ phone, token, type: 'sms'})
```
- name: Verify Signup Otp
isSpotlight: false
js: |
```js
const { data, error } = await supabase.auth.verifyOtp({ email, token, type: 'signup'})
```
auth.getSession():
title: 'getSession()'
$ref: '@supabase/gotrue-js.GoTrueClient.getSession'
@@ -191,7 +212,7 @@ pages:
const user = supabase.auth.getUser()
```
- name: Get the logged in user with a custom access token jwt.
isSpotlight: true
isSpotlight: false
js: |
```js
const user = supabase.auth.getUser(jwt)
@@ -209,13 +230,13 @@ pages:
examples:
- name: Update email for authenticated user.
description: Sends a "Confirm Email Change" email to the new email address.
isSpotlight: true
isSpotlight: false
js: |
```js
const { data, error } = await supabase.auth.updateUser({email: 'new@email.com'})
```
- name: Update password for authenticated user.
isSpotlight: true
isSpotlight: false
js: |
```js
const { data, error } = await supabase.auth.updateUser({password: 'new password'})
@@ -341,7 +362,6 @@ pages:
})
```
- name: Auto-confirm email.
isSpotlight: true
js: |
```js
const { data, error } = await supabase.auth.admin.createUser({
@@ -350,7 +370,6 @@ pages:
})
```
- name: Auto-confirm phone.
isSpotlight: true
js: |
```js
const { data, error } = await supabase.auth.admin.createUser({
@@ -382,7 +401,7 @@ pages:
- This function should only be called on a server. Never expose your `service_role` key in the browser.
examples:
- name: Basic example.
isSpotlight: false
isSpotlight: true
js: |
```js
const { data, error } = await supabase.auth.admin.inviteUserByEmail('email@example.com')
@@ -435,7 +454,7 @@ pages:
)
```
- name: Generate an invite link.
isSpotlight: true
isSpotlight: false
js: |
```js
const { data, error } = await supabase.auth.admin.generateLink(
@@ -452,7 +471,7 @@ pages:
- This function should only be called on a server. Never expose your `service_role` key in the browser.
examples:
- name: Updates a user's email.
isSpotlight: true
isSpotlight: false
js: |
```js
const { data: user, error } = await supabase.auth.admin.updateUserById(
@@ -461,7 +480,7 @@ pages:
)
```
- name: Updates a user's password.
isSpotlight: true
isSpotlight: false
js: |
```js
const { data: user, error } = await supabase.auth.admin.updateUserById(
@@ -479,7 +498,7 @@ pages:
)
```
- name: Updates a user's app_metadata.
isSpotlight: true
isSpotlight: false
js: |
```js
const { data: user, error } = await supabase.auth.admin.updateUserById(
@@ -488,7 +507,7 @@ pages:
)
```
- name: Confirms a user's email address.
isSpotlight: true
isSpotlight: false
js: |
```js
const { data: user, error } = await supabase.auth.admin.updateUserById(
@@ -497,7 +516,7 @@ pages:
)
```
- name: Confirms a user's phone number.
isSpotlight: true
isSpotlight: false
js: |
```js
const { data: user, error } = await supabase.auth.admin.updateUserById(