Pregunta

I've recently built an app using Firebase as the data store and secured it using the security rules that only the user can read and edit their data which all works fine.

But now I want to build an admin section to list users and update details if need be, but the problem I'm running into is the fact that I cant access their data as I'm not the user. I'm seeing if its possible to allow read or write permissions to the user or admin?

UPDATE

Token generation

var tokenGenerator = new FirebaseTokenGenerator(authSecret);
var token = tokenGenerator.createToken({admin: true});

Security rule

".read": "auth.admin == true || otherauthmthod"
¿Fue útil?

Solución

The method that you described above will work, assuming you update your security rules to look for the auth.admin bit. Alternatively, and likely a bit easier, is to generate an admin token, which will allow you to skip the execution of security rules entirely. This can be accomplished via:

var token = tokenGenerator.createToken({ any: "data" }, { admin: true });

See https://github.com/firebase/firebase-token-generator-node for more details.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top