import 'package:firebase_auth/firebase_auth.dart'; class AuthService { final FirebaseAuth firebaseAuth = FirebaseAuth.instance; User? get currentUser => firebaseAuth.currentUser; Stream get authStateChanges => firebaseAuth.authStateChanges(); Future signIn({ required String email, required String password }) async { return await firebaseAuth.signInWithEmailAndPassword( email: email, password: password); } Future createAccount({ required String email, required String password }) async { return await firebaseAuth.createUserWithEmailAndPassword( email: email, password: password); } Future signOut() async { await firebaseAuth.signOut(); } Future resetPassword(String email) async { await firebaseAuth.sendPasswordResetEmail(email: email); } Future updateDisplayName({ required String displayName, }) async { await currentUser!.updateDisplayName(displayName); } Future deleteAccount({ required String password, required String email, }) async { // Re-authenticate the user AuthCredential credential = EmailAuthProvider.credential(email: email, password: password); await currentUser!.reauthenticateWithCredential(credential); // Delete the user await currentUser!.delete(); await firebaseAuth.signOut(); } Future resetPasswordFromCurrentPassword({ required String currentPassword, required String newPassword, required String email, }) async { // Re-authenticate the user AuthCredential credential = EmailAuthProvider.credential(email: email, password: currentPassword); await currentUser!.reauthenticateWithCredential(credential); // Update the password await currentUser!.updatePassword(newPassword); } }