resetPassword method
- String email
Sends a password reset email
Implementation
Future<void> resetPassword(String email) async {
try {
// Pre-condition checks
if (email.isEmpty) {
throw ValidationError('Email is required');
}
await _auth.sendPasswordResetEmail(email: email);
} on FirebaseAuthException catch (e) {
// Handle specific Firebase Auth errors
switch (e.code) {
case 'invalid-email':
throw ValidationError('The email address is not valid', cause: e);
case 'user-not-found':
throw ValidationError('No user found with this email', cause: e);
default:
throw RALIException('Failed to send password reset email: ${e.message}', cause: e);
}
} catch (e) {
// Handle other error types
if (e is RALIException) {
// Already a RALIException, just rethrow
rethrow;
}
// Log the error for debugging
logError(e, StackTrace.current, context: 'resetPassword');
throw RALIException('An unexpected error occurred when sending password reset', cause: e);
}
}