Files
supabase/apps/reference/_supabase_dart/usage.mdx
T
2022-07-31 15:39:17 +02:00

116 lines
2.0 KiB
Plaintext

---
id: usage
title: Usage
---
<!-- AUTOGENERATED: DO NOT EDIT DIRECTLY IF THIS IS VERSION "next" -->
Supabase Dart.
<!-- AUTOGENERATED: DO NOT EDIT DIRECTLY IF THIS IS VERSION "next" -->
## Initializing the client library
```dart
final supabase = SupabaseClient('<SUPABASE_URL>', '<SUPABASE_ANON_KEY>');
```
### Attributes
### Notes
## Dart
You can initialize a new Supabase client using the `SupabaseClient()` method.
The Supabase client is your entrypoint to the rest of the Supabase functionality
and is the easiest way to interact with everything we offer within the Supabase ecosystem.
## Flutter
For `supabase_flutter`, you will be using the static `initialize()` method on `Supabase` class.
### Examples
####
```dart
final supabase = SupabaseClient('https://xyzcompany.supabase.co', 'public-anon-key');
```
####
```dart title="main.dart"
Future<void> main() async {
await Supabase.initialize(url: 'https://xyzcompany.supabase.co', anonKey: 'public-anon-key');
runApp(MyApp());
}
```
## Create a new user.
```dart
final res = await supabase.auth.signUp('<USER_EMAIL>', '<USER_PASSWORD>');
```
### Attributes
### Notes
- By default, the user will need to verify their email address before logging in. If you would like to change this, you can disable "Email Confirmations" by going to Authentication -> Settings on [app.supabase.com](https://app.supabase.com)
- If "Email Confirmations" is turned on, a user is returned but session will be null
- If "Email Confirmations" is turned off, both a `user` and a `session` will be returned
- When the user confirms their email address, they will be redirected to localhost:3000 by default. To change this, you can go to Authentication -> Settings on [app.supabase.com](https://app.supabase.com)
### Examples
#### Sign up.
```dart
final res = await supabase.auth.signUp('example@email.com', 'example-password');
final user = res.data?.user;
final error = res.error;
```
#### Sign up with third-party providers.
```dart
// Use signInWithProvider()
```