createUser method

Future<XauthResponse?> createUser({
  1. required String email,
  2. required String password,
  3. Map<String, dynamic>? fieldsExtention,
})

Implementation

Future<XauthResponse?> createUser(
    {required String email,
    required String password,
    Map<String, dynamic>? fieldsExtention}) async {
  try {
    var response = await _auth.createUserWithEmailAndPassword(
        email: email, password: password);
    Map<String, dynamic> data = {};
    data.addAll({'email': response.user!.email});
    data.addAll({'xuid': response.user!.uid});
    data.addAll({'date_created': Timestamp.now()});
    data.addAll({'status': 'active'});
    fieldsExtention?.forEach((key, value) {
      data.addAll({key: value});
    });
    _xModel.fields = fields;
    await _xModel.add(data);
    XauthResponse resp = XauthResponse(
        message: 'User created successfully',
        success: true,
        xDataModel: await _xModel.get('xuid', response.user!.uid));
    return resp;
  } on FirebaseAuthException catch (e) {
    return XauthResponse(
        message: e.message ?? 'An error occured',
        success: false,
        xDataModel: null);
  }
}