Initial commit
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
import 'supabase_provider.dart';
|
||||
|
||||
final authStateChangesProvider = StreamProvider<AuthState>((ref) {
|
||||
final client = ref.watch(supabaseClientProvider);
|
||||
return client.auth.onAuthStateChange;
|
||||
});
|
||||
|
||||
final sessionProvider = Provider<Session?>((ref) {
|
||||
final client = ref.watch(supabaseClientProvider);
|
||||
return client.auth.currentSession;
|
||||
});
|
||||
|
||||
final authControllerProvider = Provider<AuthController>((ref) {
|
||||
final client = ref.watch(supabaseClientProvider);
|
||||
return AuthController(client);
|
||||
});
|
||||
|
||||
class AuthController {
|
||||
AuthController(this._client);
|
||||
|
||||
final SupabaseClient _client;
|
||||
|
||||
Future<AuthResponse> signInWithPassword({
|
||||
required String email,
|
||||
required String password,
|
||||
}) {
|
||||
return _client.auth.signInWithPassword(email: email, password: password);
|
||||
}
|
||||
|
||||
Future<AuthResponse> signUp({
|
||||
required String email,
|
||||
required String password,
|
||||
String? fullName,
|
||||
List<String>? officeIds,
|
||||
}) {
|
||||
return _client.auth.signUp(
|
||||
email: email,
|
||||
password: password,
|
||||
data: {
|
||||
if (fullName != null && fullName.trim().isNotEmpty)
|
||||
'full_name': fullName.trim(),
|
||||
if (officeIds != null && officeIds.isNotEmpty) 'office_ids': officeIds,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> signInWithGoogle({String? redirectTo}) {
|
||||
return _client.auth.signInWithOAuth(
|
||||
OAuthProvider.google,
|
||||
redirectTo: redirectTo,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> signInWithMeta({String? redirectTo}) {
|
||||
return _client.auth.signInWithOAuth(
|
||||
OAuthProvider.facebook,
|
||||
redirectTo: redirectTo,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> signOut() {
|
||||
return _client.auth.signOut();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user