These are the rules for saying only a logged in user can access a document named with their user id in realtime db. I'm asking how to do this in Firestore, except the name of the documents isn't the userid, but the username (which is the first part of the email)
I have seen this done before when the document names are the uid
, but my documents names are the username of the user, and the username is stored as the part before the @
in the authentication email.
For example, I have these users:
john@gmail.com
jane@gmail.com
and my firestore is:
collection: users
john
jane
Only a user logged in as john@gmail.com
should be able to write to the john document in users. I couldn't figure out how to get the email out of the auth
variable.
Is there a way to do this without renaming my documents to user id?