Reputation: 85
I am in big trouble with firestore. here there is a link for the code sources: https://github.com/10100011001/10100011001.github.io/tree/master/public/assets/scripts
Model:
self.saveData = function(input) {
let userInfo = {
username : input.value,
userScore : self.settings.playerScore,
};
let userStr = JSON.stringify(userInfo);
localStorage.setItem('user', userStr);
let name = input.value,
score = self.settings.playerScore;
myAppDB.collection('results').doc(`player_${name.replace(/\s/g, "").toLowerCase()}`).set({
player: `${name}`,
score: `${score}`,
})
.then(function() {
console.log('result saved');
})
.catch(function(error) {
console.log('error saving result: ', error);
});
myView.clearInput(input);
myView.closeModal();
};
Controller:
self.saveData = function() { // сохраняем данные из инпута
let input = myControllerContainer.querySelector('#playerName');
myModel.saveData(input);
}
Upvotes: 1
Views: 1667
Reputation: 6309
Quoted from your comment:
these are my [security] rules ...
allow read, write: if false
Since you said if false
,
that condition will never be true,
hence your security rules will not allow you to write to your database from the front end.
You could
Edit:
Please note that while it is convenient to set your read write rules to if true
during development, that means that anyone can access your database!
I highly recommend reading the documentation on Firestore security rules, and, as soon as you have anything important in your database, developing rules to reflect appropriate access levels for yourself, your team, and your end users, registered and unregistered.
Docs: https://firebase.google.com/docs/firestore/security/overview
Upvotes: 2
Reputation: 598817
The error message you get means that your application is trying to read or write some data that you don't have access to.
All data access to Cloud Firestore is controlled by Firebase's server-side security rules, which ensure that each user can only access data they're authorized for.
To get rid of this error you need to find the exact code that is generating it. You then have two options:
Neither of these is pertinently better than the other. It all depends on the use-cases and business rules of your application.
I recommend that you read the documentation on business rules I linked above, and then also study this additional guide. With that information you should be able to fix the problem.
If you have concrete problems after this, post a question with the minimal security rules, data, and code with which anyone can reproduce the problem and we can try to help further.
Upvotes: 1