createUserWithEmailAndPassword method

  1. @override
Future<UserModel> createUserWithEmailAndPassword(
  1. String email,
  2. String password
)
override

Implementation

@override
Future<UserModel> createUserWithEmailAndPassword(
  String email,
  String password,
) async {
  try {
    final userCredential = await _auth.createUserWithEmailAndPassword(
      email: email,
      password: password,
    );

    try {
      await initializeUserClaims(userCredential.user!.uid, {
        'role': Roles.user.toString(),
      });
    } catch (e) {
      error('Warning: Unable to set default claims: ${e.toString()}');
    }

    final claims = await getUserClaims();

    return UserModel(
      uid: userCredential.user!.uid,
      email: userCredential.user!.email,
      username: userCredential.user!.displayName,
      claims: claims,
    );
  } on firebase_auth.FirebaseAuthException catch (e) {
    switch (e.code) {
      case 'email-already-in-use':
        throw EmailAlreadyInUseException();
      case 'weak-password':
        throw UserNotFoundException();
      case 'invalid-email':
        throw InvalidEmailException();
      default:
        throw UnknownAuthException(e.message ?? e.toString());
    }
  } catch (e) {
    throw UnknownAuthException(e.toString());
  }
}