register method

Future<AuthStateModel> register(
  1. String email,
  2. String password
)

Implementation

Future<AuthStateModel> register(String email, String password) async {
  var currentState = AuthStateModel.empty();

  try {
    final userModel = await _auth.createUserWithEmailAndPassword(
      email,
      password,
    );

    currentState = currentState.copyWith(
      state: AuthState.authenticated,
      user: userModel,
    );
    state = currentState;
  } on EmailAlreadyInUseException catch (e) {
    error('Auth error: Email already in use', error: e);
    currentState = currentState.copyWith(
      state: AuthState.error,
      errorMessage: e.code,
    );
    state = currentState;
  } on AuthException catch (e) {
    error('Auth error: ${e.message}', error: e);
    currentState = currentState.copyWith(
      state: AuthState.error,
      errorMessage: e.code,
    );
    state = currentState;
  } catch (e) {
    error('Unexpected auth error: ${e.toString()}', error: e);
    currentState = currentState.copyWith(
      state: AuthState.error,
      errorMessage: AuthException.unknownCode,
    );
    state = currentState;
  }

  return state;
}