cofounderella/lib/auth/auth_service.dart

41 lines
977 B
Dart
Raw Normal View History

2024-04-29 14:36:25 +02:00
import 'package:firebase_auth/firebase_auth.dart';
class AuthService {
// instance of auth
final FirebaseAuth _auth = FirebaseAuth.instance;
//sign in
Future<UserCredential> signInWithEmailPassword(String email, password) async {
try {
UserCredential userCredential = await _auth.signInWithEmailAndPassword(
email: email,
password: password,
);
return userCredential;
} on FirebaseAuthException catch (e) {
throw Exception(e.code);
}
}
// sign up (register)
Future<UserCredential> signUpWithEmailPassword(String email, password) async {
try {
UserCredential userCredential =
await _auth.createUserWithEmailAndPassword(
email: email,
password: password,
);
return userCredential;
} on FirebaseAuthException catch (e) {
throw Exception(e.code);
}
}
// sign out
Future<void> signOut() async {
return await _auth.signOut();
}
// errors
}