mirror of
https://github.com/supabase/supabase.git
synced 2026-07-05 02:24:20 +08:00
134 lines
2.8 KiB
Plaintext
134 lines
2.8 KiB
Plaintext
---
|
|
id: auth-email
|
|
title: 'Login With Email'
|
|
description: Use Supabase to Authenticate and Authorize your users using email.
|
|
---
|
|
|
|
import Tabs from '@theme/Tabs'
|
|
import TabsPanel from '@theme/TabsPanel'
|
|
|
|
## Overview
|
|
|
|
Setting up Email logins for your Supabase application.
|
|
|
|
- Add Email 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 Email 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
|
|
|
|
The JavaScript client code is documented here: [Supabase OAuth Client Code](/docs/reference/javascript/auth-signin#sign-in-using-third-party-providers)
|
|
|
|
<Tabs
|
|
defaultActiveId="js"
|
|
groupId="guides/auth"
|
|
values={[{ label: 'JavaScript', value: 'js' }, { label: 'Dart', value: 'dart' }]}
|
|
>
|
|
|
|
<TabsPanel id="js" label="js">
|
|
|
|
```js
|
|
const { user, error } = await supabase.auth.signIn({
|
|
email: 'example@email.com',
|
|
password: 'example-password',
|
|
})
|
|
```
|
|
|
|
</TabsPanel>
|
|
|
|
<TabsPanel id="dart" label="dart">
|
|
|
|
```dart
|
|
final res = await supabase.auth.signIn(
|
|
email: 'example@email.com',
|
|
password: 'example-password'
|
|
);
|
|
|
|
final user = res.data?.user;
|
|
final error = res.error;
|
|
```
|
|
|
|
</TabsPanel>
|
|
|
|
</Tabs>
|
|
|
|
Add this function which you can call from a button, link, or UI element.
|
|
|
|
<Tabs
|
|
defaultActiveId="js"
|
|
groupId="guides/auth"
|
|
values={[{ label: 'JavaScript', value: 'js' }, { label: 'Dart', value: 'dart' }]}
|
|
>
|
|
|
|
<TabsPanel id="js" label="js">
|
|
|
|
```js
|
|
async function signInWithEmail() {
|
|
const { user, error } = await supabase.auth.signIn({
|
|
email: 'example@email.com',
|
|
password: 'example-password',
|
|
})
|
|
}
|
|
```
|
|
|
|
</TabsPanel>
|
|
|
|
<TabsPanel id="dart" label="dart">
|
|
|
|
```dart
|
|
function SignInWithEmail() {
|
|
await supabase.auth.signIn(
|
|
email: 'example@email.com',
|
|
password: 'example-password'
|
|
);
|
|
}
|
|
```
|
|
|
|
</TabsPanel>
|
|
|
|
</Tabs>
|
|
|
|
To log out:
|
|
|
|
<Tabs
|
|
defaultActiveId="js"
|
|
groupId="guides/auth"
|
|
values={[{ label: 'JavaScript', value: 'js' }, { label: 'Dart', value: 'dart' }]}
|
|
>
|
|
|
|
<TabsPanel id="js" label="js">
|
|
|
|
```js
|
|
async function signOut() {
|
|
const { error } = await supabase.auth.signOut()
|
|
}
|
|
```
|
|
|
|
</TabsPanel>
|
|
|
|
<TabsPanel id="dart" label="dart">
|
|
|
|
```dart
|
|
function SignOut() {
|
|
await supabase.auth.signOut();
|
|
}
|
|
```
|
|
|
|
</TabsPanel>
|
|
|
|
</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)
|