How to specify an effective uid when accessing Realtime Database with the admin SDK on node

前端 未结 1 1173
梦如初夏
梦如初夏 2021-01-17 05:55

I am new to node.js. I have a created a database with users node. Users node is protected with the following rules.

{
  \"rules\": {
    \"users\":{
                 


        
相关标签:
1条回答
  • 2021-01-17 06:27

    This is described in the documentation:

    On your server, when you initialize the Firebase app, use the databaseAuthVariableOverride option to override the auth object used by your database rules. In this custom auth object, set the uid field to the identifier you used to represent your service in your Security Rules.

    // Initialize the app with a custom auth variable, limiting the server's access
    admin.initializeApp({
      credential: admin.credential.cert(serviceAccount),
      databaseURL: "https://databaseName.firebaseio.com",
      databaseAuthVariableOverride: {
        uid: "my-service-worker"
      }
    });
    
    0 讨论(0)
提交回复
热议问题