cofounderella/lib/services/auth/auth_service.dart

54 lines
1.2 KiB
Dart

import 'package:firebase_auth/firebase_auth.dart';
import '../swipe_stream_service.dart';
class AuthService {
// instance of auth
final FirebaseAuth _auth = FirebaseAuth.instance;
// get current user
User? getCurrentUser() {
return _auth.currentUser;
}
/// sign in (login)
///
/// @throws FirebaseAuthException
Future<UserCredential> signInWithEmailPassword(String email, String password) async {
try {
UserCredential userCredential = await _auth.signInWithEmailAndPassword(
email: email,
password: password,
);
return userCredential;
} on FirebaseAuthException {
rethrow;
}
}
/// sign up (register)
///
/// @throws FirebaseAuthException
Future<UserCredential> signUpWithEmailPassword(String email, password) async {
try {
// create user
UserCredential userCredential =
await _auth.createUserWithEmailAndPassword(
email: email,
password: password,
);
return userCredential;
} on FirebaseAuthException {
rethrow;
}
}
// sign out
Future<void> signOut() async {
SwipeStreamService().stopListening();
await _auth.signOut();
}
}