updateUserProfile method
Implementation
@override
Future<UserModel> updateUserProfile({String? username, String? email}) async {
final user = _auth.currentUser;
if (user == null) {
throw UserNotFoundException();
}
try {
if (email != null && email != user.email) {
await user.verifyBeforeUpdateEmail(email);
}
if (username != null && username != user.displayName) {
await user.updateDisplayName(username);
}
final claims = await getUserClaims();
return UserModel(
uid: user.uid,
email: email ?? user.email,
username: username ?? user.displayName,
claims: claims,
);
} on firebase_auth.FirebaseAuthException catch (e) {
switch (e.code) {
case 'invalid-email':
throw InvalidEmailException();
case 'requires-recent-login':
throw RecentLoginRequiredException();
default:
throw UnknownAuthException(e.message ?? e.toString());
}
} catch (e) {
if (e is AuthException) {
rethrow;
}
throw UnknownAuthException(e.toString());
}
}