I have a react redux firebase app with a content management side (all those pages start with /admin/...
). I need to restrict firebase database and firebase storage write access to a small subset of those users, as well as handle a redirect when an unauthenticated (or authenticated without admin role) user tries to go there. Currently, anyone who figures out that the auth buttons are at /admin
can log in with facebook or google, then have access to everything.
From what I've read, it looks like one does this via custom tokens, but I'm unclear on where to put the snippets they provide to do this securely. I tried manually adding admin: true
inside the firebase database via the web console, then set up my firebase database rules like so:
{
"rules": {
".read": "true",
".write": "auth != null && root.child('users').child(auth.uid).child('admin').val() == true"
}
}
This seems to work in terms of protecting write access to the database, but I was unable to use the same admin field/token for firebase storage, so I had to do this:
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if request.auth!=null && request.auth.uid=="{my uid}";
//request.auth.token.admin==true did not seem to work
}
}
}
I also couldn't get that admin: true
to show up on the client, so I don't have a way of of redirecting right now.
Can someone please clear this up for me?