f-miyu / Plugin.CloudFirestore

MIT License
121 stars 44 forks source link

firestore: PERMISSION_DENIED: Missing or insufficient permissions #80

Open ourweb4 opened 3 years ago

ourweb4 commented 3 years ago

I am creating a auth user but when i go to create some data I'm getting this error.

My Rule:

rules_version = '2'; service cloud.firestore { match /databases/{database} {

  allow read, update, delete: if true;
  allow create: if true;
}

}

My Code:

  private async void  save_Clicked(object sender, EventArgs e)
    {
        var em = txtemail.Text;
        var pw = txtpassword.Text;
        if (em != null && pw != null )
        {
            var result = await CrossFirebaseAuth.Current.Instance.CreateUserWithEmailAndPasswordAsync(em, pw);
            var uid = result.User.Uid;
            if (uid != null)
            {
                User user = new User();
                var app = Application.Current as App;
                app.ukey = uid;
                user.Uid = uid;
                user.address = txtaddress.Text;
                user.city = txtcity.Text;
                user.email = em;
                user.first = txtfirstname.Text;
                user.phone = txtphone.Text;
                user.state = txtstate.Text;
                user.zip = txtzip.Text;
                user.last = txtlastname.Text;
                await CrossCloudFirestore.Current
                     .Instance
                     .Collection("users")

                     .AddAsync<User>(user);

               await Navigation.PopAsync(false);
            } else
            {
               await  DisplayAlert("Error", "User cant be created ", "OK");

            }
        }
        else
        {
           await  DisplayAlert("Error", "Email/password cant be blank", "OK");
        }

    }
}

}

DagobertDev commented 3 years ago

Firestore rules only apply to the specified path, not to any sub-paths. To allow anything use:

match /databases/{database}/documents/{document=**} {
      allow read, write;
}