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:
I had use this and it worked. Basically I make sure the user is logged in by request.auth != null
and then I check to see if the resource requested is null. If the resource already exists, then it means the user exists.
I added in the allow update
in case you wanted only the user to change their own data.
match /users/{document} {
allow create: if request.auth != null && resource == null;
allow update: if request.auth != null && request.auth.uid == resource.data.author_uid;
}