mirror of
https://github.com/supabase/supabase.git
synced 2026-10-14 13:49:09 +03:00
102 lines
2.8 KiB
Plaintext
102 lines
2.8 KiB
Plaintext
---
|
|
id: auth-magic-link
|
|
title: 'Login With Magic Link'
|
|
description: Use Supabase to authenticate and authorize your users using magic links.
|
|
---
|
|
|
|
import Tabs from '@theme/Tabs'
|
|
import TabItem from '@theme/TabItem'
|
|
|
|
Magic links are a form of passwordless logins where users click on a link sent to their email address to log in to their accounts.
|
|
Magic links only work with email addresses. By default, a user can only request a magic link once every 60 seconds.
|
|
|
|
## Overview
|
|
|
|
Setting up Magic Link logins for your Supabase application.
|
|
|
|
- Add Magic Link authenticator to your [Supabase Project](https://app.supabase.com)
|
|
- Add the login code to your application - [JavaScript](https://github.com/supabase/supabase-js) | [Dart](https://github.com/supabase/supabase-dart)
|
|
|
|
## Add Magic Link into your Supabase Project
|
|
|
|
- Go to your [Supabase Project Dashboard](https://app.supabase.com)
|
|
- In the left sidebar, click the `Authentication` icon (near the top)
|
|
- Click `Settings` from the list to go to the `Authentication Settings` page
|
|
- Enter the final (hosted) URL of your app under `Site URL` (this is important)
|
|
- Under `Email Auth` turn `Enable Email Signup` to ON
|
|
- Click `Save`
|
|
|
|
## Add login code to your client app
|
|
|
|
<Tabs
|
|
defaultValue="js"
|
|
groupId="guides/auth"
|
|
values={[{ label: 'JavaScript', value: 'js' }, { label: 'Dart', value: 'dart' }]}
|
|
>
|
|
|
|
<TabItem value="js">
|
|
|
|
When your user signs in, call [signInWithOtp()](/docs/reference/javascript/auth-signinwithotp) with their email address:
|
|
|
|
```js
|
|
async function signInWithEmail() {
|
|
const { data, error } = await supabase.auth.signInWithOtp({
|
|
email: 'example@email.com',
|
|
})
|
|
}
|
|
```
|
|
|
|
</TabItem>
|
|
|
|
<TabItem value="dart">
|
|
|
|
When your user signs in, call [signIn()](/docs/reference/dart/auth-signin) with their email address:
|
|
|
|
```dart
|
|
Future<void> signInWithEmail() async {
|
|
await supabase.auth.signIn(email: 'example@email.com');
|
|
}
|
|
```
|
|
|
|
</TabItem>
|
|
|
|
</Tabs>
|
|
|
|
<Tabs
|
|
defaultValue="js"
|
|
groupId="guides/auth"
|
|
values={[{ label: 'JavaScript', value: 'js' }, { label: 'Dart', value: 'dart' }]}
|
|
>
|
|
|
|
<TabItem value="js">
|
|
|
|
When your user signs out, call [signOut()](/docs/reference/javascript/auth-signout) to remove them from the browser session and any objects from localStorage:
|
|
|
|
```js
|
|
async function signOut() {
|
|
const { error } = await supabase.auth.signOut()
|
|
}
|
|
```
|
|
|
|
</TabItem>
|
|
|
|
<TabItem value="dart">
|
|
|
|
When your user signs out, call [signOut()](/docs/reference/dart/auth-signout) to remove them from the browser session and any objects from localStorage:
|
|
|
|
```dart
|
|
Future<void> signOut() async {
|
|
await supabase.auth.signOut();
|
|
}
|
|
```
|
|
|
|
</TabItem>
|
|
|
|
</Tabs>
|
|
|
|
## Resources
|
|
|
|
- [Supabase Account - Free Tier OK](https://supabase.com)
|
|
- [Supabase JS Client](https://github.com/supabase/supabase-js)
|
|
- [Supabase Dart Client](https://github.com/supabase/supabase-dart)
|