Nuxtjs / Firebase权限被拒绝

问题描述 投票:0回答:1

无法使用nuxt-community的firebase模块链接here从firebase实时数据库中读取/检索数据。已经在nuxt.config.js文件中添加了我的firebase配置,如下所示。

modules: [
    '@nuxtjs/dotenv',
    [
      '@nuxtjs/firebase',
      {
        config: {
          apiKey: process.env.API_KEY,
          authDomain: process.env.AUTH_DOMAIN,
          databaseURL: process.env.DATABASE_URL,
          projectId: process.env.PROJECT_ID,
          storageBucket: process.env.STORAGE_BUCKET,
          messagingSenderId: process.env.MESSAGING_SENDER_ID,
          appId: process.env.APP_ID,
          measurementId: process.env.MEASUREMENT_ID,
          databaseSecret: process.env.DATABASE_SECRET,
        },
        services: {
          auth: true,
          realtimeDb: true,
        }
      }
    ],
  ],

规则:我不确定这是否正确。我只想将读取权限限制为仅限我自己。

{
  "rules": {
    ".read": "auth.uid === 'my-uid-here'",
    ".write": "false"
  }
}

SomeComponent.vue

async loadFromDb() {
      const messageRef = this.$fireDb.ref('cases')
      try {
        const snapshot = await messageRef.once('value')
        alert(snapshot.val().cases)
      } catch (e) {
        alert(e)
        return
      }
},
javascript firebase firebase-realtime-database nuxt.js firebase-security
1个回答
1
投票

您正在尝试从/cases中读取内容,而您的安全规则仅授予对/users的读取权限。如果您想读取/cases(也是),则必须授予对/cases(也是)的读取权限。

{
  "rules": {
    "users": {
      "$uid": {
        ".read": "$uid === auth.uid",
        ".write": "false"
      }
    },
    "cases": {
      ".read": true
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.