Using Firebase Firestore (V2.0 rules)
When registering a user in my application I am creating a custom claim and passing an id to the token to ensure the user can only read/write data to collections where they are a group participant.
An example looks like:
match /questionnaire/{questionnaireId}{
allow read, get,
list: if request.auth.token.participantId in resource.data.participants ||
isAdmin()
allow create,
update: if isAdmin();
allow delete: if
false;
}
IsAdmin is a custom
claim where {admin:true} and the other custom claim is set when the participant
registers with the application, I am setting a participantId as a custom
claim on their user token. So it looks like
{participantId : 1234}
The rules work, I have hundreds of unit tests that prove they do. When the user registers, I send email verification to their email account provided and they have to verify their email before they can login.
Once in a while when the user tries to login for the first time, they receive a permission denied error on one or more of the collections. Then if they clear caches and login the user is allowed to proceed without error.
Is there a local copy of the rules in the browser cache that could be causing this very hard to replicate (but very important) error?
It seems to happen frequently when creating new users and logging them in the first time. Something that will probably never happen IRL but happens enough during our UAT testing that its raising client’s eyebrows.
Any/all replies appreciated.
MG
--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/89189d7f-818e-456a-bfc0-97b74ef19486n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/77340efd-0bd3-47b2-a5af-9b8cc9412fc3n%40googlegroups.com.
After new claims are modified on a user via the Admin SDK, they are propagated to an authenticated user on the client side via the ID token in the following ways:A user signs in or re-authenticates after the custom claims are modified. The ID token issued as a result will contain the latest claims.An existing user session gets its ID token refreshed after an older token expires.An ID token is force refreshed by calling currentUser.getIdToken(true).
secondaryApp.auth().createUserWithEmailAndPassword(user.userName, user.password)
.then(result => {
uid = result.user.uid;
currentUser = secondaryApp.auth().currentUser;
...
const fbFunctions = secondaryApp.functions(); const setParticpantId = fbFunctions.httpsCallable('setParticpantId'); setParticpantId({email: currentUser.userName}).then(function (result) { secondaryApp.auth().signOut(); }).catch((err) => { secondaryApp.auth().signOut();})...});
The user is also forced to validate their email address before they can use the app. If they try to login before their email address has been validated we warn them and log them out.
By the time they actually login, it is my understanding the token they get at that time should contain the custom claim, as it was set during the resolve promise of the createUserWithEmailAndPassWord api call.
Does this seem correct?
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/CAHafJBrWNO6K_Z6T%2BuEj4%2BGVGx6PqL4xfYpO%3DryFDyeukkq-aA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/CAFhAot7w%2BQG%3DpCjp26QtjaMeCyn_CmQtxK_Oy__qX5tV7U4j3g%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/CAHafJBr6NvdbeoGRpHLpeOaGs_EAijB3HBv-7DXhZ5wKag40ZA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/CAFhAot4gUEmsn%2BDDfF6SLjB1OWG4CDiuQPz65otySnDyxcuMWw%40mail.gmail.com.