Supabase is a cloud-based platform for building scalable and secure backend applications.
First we have to start the supabase
Future<void> main() async {
await Supabase.initialize(
url: 'https://xyzcompany.supabase.co',
anonKey: 'public-anon-key',
);
runApp(MyApp());
}
// Get a reference your Supabase client
final supabase = Supabase.instance.client;
SignUp a user
// create email account
Future<void> createAccountEmail(String email, String password,
{Function(AuthException)? onError}) async {
try {
final response = await _supabaseClient.auth.signUp(
email: email,
password: password,
);
final session = response.session;
final user = response.user;
} on AuthException catch (error) {
//error
onError?.call(error);
}
LogIn a user
// login account with email
Future<void> logInAccountEmail(String email, String password,
{Function(AuthException)? onError, Function()? onDone}) async {
try {
final AuthResponse res = await supabase.auth.signInWithPassword(
email: email,
password: password,
);
final Session? session = res.session;
final User? user = res.user;
onDone?.call();
} on AuthException catch (error) {
// if there is an error with the log in, the function specified by the user can be executed
onError?.call(error);
}
}