I have been searching in this forum that has helped me a lot to develop my entire project in firebase but I have not been able to find the answer to my question.
I have created a small voting app where users register and can only vote if they have verified their email. Every time a user registers, a verification email is sent with the sendEmailVerification()
method. Obviously I can (and I will) hide/show the UI based on user.emailVerified
value (true or false) but for more security, I have configured the following rules:
{
"rules": {
//only users can write, noone can read
".read": false,
".write": "auth.uid != null",
"users": {
"$uid": {
//Inside /users, users can read/write in child /$uid only if the $uid of the user matches with the /$uid that is the branch name for each user
".read": "$uid === auth.uid",
".validate": "$uid === auth.uid",
"votos": {
//only users that verified the email can read/write in this child object
".validate": "auth.token.email_verified === true",
}
}
},
"lists": {
//only users that verified the email can read/write here
//read is public because you dont need to be logged in to see the votes of the lists
".read": true,
".validate": "auth.token.email_verified == true",
}
}
}
I have done tests in the console simulator and everything seems to work correctly but when I go to the web it does not let me vote even though I have verified my email.
Basically I can only think of:
- I have not configured the rules correctly (but the console simulator gives me the results I expect)
- I have not configured the validations correctly
- It is not enough to send the verification email. Could it be that when the user verifies the mail, a token or something should be included in the url or in the user's data? I believe that
".validate": "auth.token.email_verified === true",
is done with the true or false value ofuser.emailVerified
of the user, but I am not an expert in this...
The only thing I've seen similar is problems related to user.emailVerified
not being updated after clicking the verification link and this made the value always false. But again, I have no idea.
If anyone can help me, I really appreciate it. This is my first question on the forum, sorry if I did something wrong.