Firebase rules and permissions

Hi

I’m tring to setup a realtime database with firebase. I’m getting problems about the rules. I wrote this simple rules:

service cloud.firestore {
  match /databases/{database}/documents {
    match /players/{playerId}  {
     allow read, write: if request.auth.uid == playerId;
    }
  }
}

And this is my method to auth the user with sms:

firebase.auth()
                 .signInWithPhoneNumber(phoneNumberString, appVerifier)
                 .then(confirmationResult => {
                  // other code and wait user to insert the code and send it with an action listener on a button
                  firebase.auth().onAuthStateChanged((user) => {
                                    if (user) {
                                         // here I write a user in my db
                                    }
                  });
        });

But after the user insert the right code sent by firebase, and he is authenticated, firebase return me he has not the right permission to write.

How should I fix it to make it works, because I’m not figure out and online I didn’t find anything that could help me.

Thanks

Try the emulator in your firebase console where u can set the ruled

There it can tell you which rules kicks you

I’m sure it is the second one becouse if I set rules on no security It works