What I am trying to achieve is very simple. I need to create a user entry in the database only if it doesn\'t exist.
The app flow:
Use logic in your code, but not in rules. Add addOnCompleteListener to user collection and after get the result do some actions.
getUsers.document(userUID).get().addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task doc) {
if(!doc.getResult().exists()){
//add new user
}
}
}
Rules:
match /UsersProfile/{document=**} {
allow read, write: if request.auth != null;
}