I found this question: Firebase Permission Denied which mentions using this JSON code:
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
It only allows access to Read or Write by authenticated users. This would work perfectly for me.
The only issue is that this answer is outdated. They dont use JSON anymore as far as I know.
Currently my rules look like this:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
}
}
How can I allow only Read and Write access to users with the "API Key" which I have provided and loaded in my app like in the old question?
Edit, I now know that Firebase Realtime Database uses JSON Rules and Firebase Firestore uses the actual Firebase Security Rules Language.
So after I realized this, I set all my rules to auth != null.
In realtime database rules:
{
"rules": {
"users": {
".read": "auth != null",
".write": "auth != null"
}
}
}
And also Cloud Storage rules just in case:
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if request.auth != null;
}
}
}
Yet after all of this... Im still getting these errors:
I dont get what Im doing wrong, Im directly sending in the API key correctly, I logged it just to test it, all my references are correct...
I DONT GET IT....
EDIT: Code
const firebase = require('firebase');
var config = {
apiKey: "(Key removed... for obvious reasons)",
authDomain: "discord-trust.firebaseapp.com",
databaseURL: "https://discord-trust.firebaseio.com",
storageBucket: "discord-trust.appspot.com"
};
firebase.initializeApp(config);
... Lots of code between these two ...
case `testWriteReputation`: {
if (msg.author.bot) return;
if (msg.author.id === bot.user.id) return;
firebase.database().ref(`BasicUserData/${msg.author.id}`).set({
lastLoggedUsername: msg.author.tag,
lastLoggedAvatar: msg.author.avatar,
lastLoggedDiscriminator: msg.author.discriminator,
userAccountCreated: msg.author.createdAt,
userIdentifier: msg.author.id
});
break;
}
Entire javascript file can be found here, again, with the api key removed: https://hatebin.com/egchvudbew