Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a way to authenticate user role in firebase storage rules? [duplicate]

I am trying to restrict firebase storage based on user role.

Database:
    users
        <uid>
            admin=false
            ... ... ...

I am trying to use the following kind of rule in firebase storage:

root.child('users').child(auth.uid).child('user').child('admin').val() == true

I am getting access denied after adding this to the write rule.

Thanks.

like image 832
Ahsan Avatar asked Oct 18 '22 03:10

Ahsan


1 Answers

As Frank van Puffelen pointed out in his comment:

function isAdminUser() {
    return request.auth.uid in {
        "yaddayadddayaddUserIDKey":"User Name1"
    };
}

service firebase.storage {
    match /b/<appName>.appspot.com/o {
        match /{allPaths=**} {
            allow read;
            allow write: if request.auth != null && isAdminUser();
        }
   }
}
like image 186
Ahsan Avatar answered Oct 21 '22 05:10

Ahsan