setUserData method

Future<Map<String, dynamic>?> setUserData(
  1. String userId,
  2. Map<String, dynamic> newDoc, {
  3. bool authDataMustExist = true,
})

sets the current user data to the newDoc remove the old document and add the newDoc instead (the _id can't be changed and can't be deleted) if the _id isn't presented in the newDoc no worries it will be the same if the user data doesn't exist it will create a new document with the provided user data

Implementation

Future<Map<String, dynamic>?> setUserData(
  String userId,
  Map<String, dynamic> newDoc, {
  /// this will make sure that the auth data for user exist first before setting the
  /// user data
  bool authDataMustExist = true,
}) async {
  if (authDataMustExist) {
    AuthModel? authModel =
        await _authService.authDbProvider.getUserById(userId);
    if (authModel == null) {
      throw NoUserRegisteredException();
    }
  }
  return userDataDbProvider.setUserData(userId, newDoc);
}