I have a web app(upload.html) to upload files and data on firebase. I need to login (on index.html) to access upload.html .I can upload file to firebase on test mode but when I apply rules I can't upload file even if I'm authenticated (logged in). My goal is to allow only authenticated users to write data.
upload.js
//redirect to login page if user is not logged in
firebase.auth().onAuthStateChanged((user) => {
if(!user){
location.replace('./index.html');
}
});
Firebase Rules:
Storage:
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read;
allow write: if request.auth != null; //this line is making problem
}
}
}
Database:
{
"rules": {
".read": true,
".write": "auth != null" //problem on this line
}
}