Am calling these functions in sequence (javascript 'firebase`):
firebase
.auth()
.signInWithEmailLink(email, url)
.then(userCred => {
return firebase.firestore().collection('users').doc('someDocID').get()
....
I have security rules setup in firestore that allows read of 'users/:docId' only if the email field in that document equals the auth email:
allow get: if request.auth.token.email == resource.data.email
The problem is we get a missing or insufficient permissions error on the get().
For sure the email in the database is correct so the only problem could be is that request.auth.token.email is not valid.
Could it be that signing in (using any sign in function), even if resolves, doesn't guarantee the auth token is updated and can be immediately used ?
Is there propagation time? should we call getIdToken() after sign in resolves to make sure the token is valid before making database/firestore calls?
signInWithEmailLinkwill get an ID token with the latest values, which is then cached for about an hour. Are you saying that you actively sign in by callingsignInWithEmailLinkand see outdated properties? Can you log those in your code and show the updated code and its output? - Frank van Puffelenget()called right after sign in resolves fails with a permissions problem. My understanding of your comment - after sign in resolves there should be no issue with the token sent to FS rules so its safe to use it that way - and thats what I'm trying to verify. - Shai Ben-Tovim