FirebaseError:权限缺失或不足。-类星体和 Firebase

Edw*_*nag 3 permissions firebase quasar google-cloud-firestore quasar-framework

我使用 Quasar 和 Firebase

我收到 FirebaseError:权限缺失或不足。控制台上出现错误

错误

脚本:

    // 从 firebase 获取
const 路径 = "/newpage";
    this.$auth.onAuthStateChanged(authUser => {
如果(authUser){
 
this.$bind('userz', this.$db.collection('users'));
 this.$db.collection('users').doc(authUser.uid).get()
              .then(快照=> {
                const userData = snapshot.data();
                控制台.log(用户数据);

 (this.$route.path !== 路径);
  this.$router.push(path).catch(err => {});

 this.livePaper = false;


   })} 别的 {
    
 this.livePaper = true;
console.log('用户已退出');
this.$router.push('/Login').catch(err => {});

}   
    })

  },

每当我把

```this.$bind('userz', this.$db.collection('users'));```
Run Code Online (Sandbox Code Playgroud)

发生缺少权限的情况

但是当我删除绑定时它没有错误

虽然我想获取用户名:字段中的值并将其放在我的导航上

firebase - 用户名

``` <li v-for="(users, uid) in userz" :key="uid">
      {{users.username}} <q-btn v-on:click="livePaper = true"   label="Sign Out" @click="logOut()" color="green"/>
Run Code Online (Sandbox Code Playgroud) ````

但我无法得到它,除非我删除

```this.$db.collection('users').doc(authUser.uid).get()
          .then(snapshot => {
            const userData = snapshot.data();
            console.log(userData);```
Run Code Online (Sandbox Code Playgroud)

当我删除它时,再次发生缺少权限的情况。

我应该怎么办

整个代码:

<template>
  <q-layout view="hHh lpR fFf">

    <q-header elevated class="bg-primary text-white">
      <q-toolbar>
      
        <q-btn  v-if="!livePaper" dense flat round icon="menu" @click="left = !left" />

        <q-toolbar-title>
          <q-avatar>
            <img src="https://cdn.quasar.dev/logo/svg/quasar-logo.svg">
          </q-avatar>
          Title
        </q-toolbar-title>
 <div class="q-pa-md hid" v-if="!livePaper">
  
   <li v-for="(users, uid) in userz" :key="uid">
          {{users.username}} <q-btn v-on:click="livePaper = true"   label="Sign Out" @click="logOut()" color="green"/>
   </li>
  </div>
       
      </q-toolbar>
    </q-header>

       <q-drawer v-if="!livePaper" show-if-above v-model="left" side="left"  bordered>

      <!-- drawer content -->
       <q-scroll-area style="height: calc(100% - 150px); margin-top: 150px; border-right: 1px solid #ddd">
       <q-list padding>
            <q-item clickable v-ripple>
              <q-item-section avatar>
                <q-icon name="inbox" />
              </q-item-section>
 <q-item-section>
                Inbox
              </q-item-section>
            </q-item>

            <q-item   clickable v-ripple>
              <q-item-section avatar>
                <q-icon name="star" />
              </q-item-section>

              <q-item-section>
                
                Star
              </q-item-section>
            </q-item>

            <q-item clickable v-ripple>
              <q-item-section avatar>
                <q-icon name="send" />
              </q-item-section>

              <q-item-section>
                Send
              </q-item-section>
            </q-item>

            <q-item clickable v-ripple>
              <q-item-section avatar>
                <q-icon name="drafts" />
              </q-item-section>

              <q-item-section>
                Drafts
              </q-item-section>
            </q-item>

             <q-item @click="icon = true" clickable v-ripple>
              <q-item-section avatar>
                 <q-dialog v-model="icon">
      <q-card style="width: 570px; max-width: 80vw;" class= "q-pa-xl ">
        <q-card-section class="row items-center q-pb-none ">
          <div class="text-h6">Sign Up</div>
          <q-space />
          <q-btn icon="close" flat round dense v-close-popup />
        </q-card-section>

         <q-separator />


   <q-card-section >
          <q-input filled v-model="usrnm" label="Username" id="usrnm" lazy-rules
       :rules="[ val => val && val.length > 0 || 'Please type something']"
      />

          <q-input filled v-model="eml" label="Email" id="eml" lazy-rules
       :rules="[ val => val && val.length > 0 || 'Please type something']"
      />

      <q-input
        filled
        type="password"
        v-model="pswrd"
        id="pswrd"
        label="Password"
        lazy-rules
         :rules="[ val => val && val.length > 0 ||'Please type a real age'
        ]"
      />

      <div>
        <q-btn label="Sign Up" type="submit" color="primary"  @click="signUps()" />
      
      </div>
        </q-card-section>
      </q-card>
    </q-dialog>
                <q-icon name="person_add" />
              </q-item-section>

              <q-item-section>
                Sign Up
              </q-item-section>
            </q-item> 

          </q-list>
        </q-scroll-area>
           
        <q-img class="absolute-top" src="https://cdn.quasar.dev/img/material.png" style="height: 150px">
          <div class="absolute-bottom bg-transparent">
            <q-avatar v-ripple size="56px" class="q-mb-sm">
              <img src="https://cdn.quasar.dev/img/boy-avatar.png">
            </q-avatar>
            <div class="text-weight-bold"></div>
            <div>@rstoenescu</div>
          </div>
        </q-img>
    </q-drawer>


    <q-page-container>
      <router-view />
    </q-page-container>

  </q-layout>
</template>

<script>
export default {
  data () {
    return {
      left: false,
      userz: [],
      livePaper: false,
        icon: false,
         eml: '',
      pswrd: '',
      usrnm: '',
      index: 0

    }
  },
  created() {

    // gets from the firebase
const path = "/newpage";
    this.$auth.onAuthStateChanged(authUser => {
if (authUser) {
 

 this.$db.collection('users').doc(authUser.uid)
              .get()
              .then(snapshot => {
                const userData = snapshot.data();
                console.log(userData);

 (this.$route.path !== path);
  this.$router.push(path).catch(err => {});
  this.$bind('userz', this.$db.collection('users').doc(authUser.uid));
    this.$bind('userz', this.$db.collection('users'));
 this.livePaper = false;


   })} else  {
    
 this.livePaper = true;
console.log('user logged out'); 
this.$router.push('/Login').catch(err => {});

}   
    })

  },
  methods: {

        logOut(){

   this.$auth.signOut();
 this.livePaper = true;
   },
 
                      
      signUps()  {
 this.$auth.createUserWithEmailAndPassword(this.eml, this.pswrd).then(cred => {
return this.$db.collection('users').doc(cred.userz.uid).set({
  email: this.eml,
  username: this.usrnm
});


      this.isEdit = false
      this.text = ''
      this.yr = ''
 }).then;(() => {


 });
  // ...
}
  }
}
</script> ```


  
Run Code Online (Sandbox Code Playgroud)

小智 5

这可能是 firestore 的重复线程 : PERMISSION_DENIED:缺少或不足的权限,至少这是我获得此问题帮助的地方。

以正确的方式设置规则后,错误就会消失。我对 quasar firebase 示例应用程序也遇到了同样的问题。

以下是 Firebase 规则的文档,其中包含设置规则的所有详细信息:

https://firebase.google.com/docs/firestore/security/get-started

基本上是线

allow read, write: if false;
Run Code Online (Sandbox Code Playgroud)

是这个问题,您可以将其更改为以下内容,以仅允许登录用户访问数据库:

allow read, write: if request.auth != null;
Run Code Online (Sandbox Code Playgroud)

不推荐使用以下代码,因为它允许对数据库进行未经身份验证的访问,因此除非您处于测试场景中,否则不要使用它:

allow read, write: if false;
Run Code Online (Sandbox Code Playgroud)