I have firestore rules like this:
match /{document=**} {
allow read, write: if request.auth.token.name == "dummyUser";
}
Now when I createUserWithEmailAndPassword, after I created the user, I set the displayName to "dummyUser" like this, with method setUsersSecureName() that I made:
fun setUsersSecureName(myCallback: (Boolean?) -> Unit) {
val user = FirebaseAuth.getInstance().currentUser
val profileUpdates = UserProfileChangeRequest.Builder()
.setDisplayName("dummyUser")
.build()
user?.updateProfile(profileUpdates)
?.addOnCompleteListener { task ->
if (task.isSuccessful) {
Log.d(TAG_HELPER_METHODS, "Secure user profile updated.")
myCallback(true)
}
}
}
I do the same for anonymous logins also. So I create anonymous log in like this:
auth.signInAnonymously()
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG_MAIN, "signInAnonymously:success")
val user = auth.currentUser
setUsersSecureName(){
makeRequest()
}
As you see, after login is successful with anonymous user, I change the users name. Now it seems to be changed, when I check it, the users displayName is "dummyUser". However, the firestore request doesn't work, and I get the message in the log:
PERMISSION_DENIED: Missing or insufficient permissions.
This is also not working when users are signed in with email and password. Why would this be?
Thanks