FirebaseError:缺少权限或权限不足。 -quasar和Firebase

时间:2020-06-22 16:57:04

标签: firebase google-cloud-firestore permissions quasar-framework quasar

我正在使用类星体和Firebase

我得到FirebaseError:缺少权限或权限不足。控制台错误

error

脚本:

    // gets from the firebase
const path = "/newpage";
    this.$auth.onAuthStateChanged(authUser => {
if (authUser) {
 
this.$bind('userz', this.$db.collection('users'));
 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.livePaper = false;


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

}   
    })

  },

无论何时我放

```this.$bind('userz', this.$db.collection('users'));```

发生权限丢失

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

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

firebase - username

``` <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"/>
```

但除非删除,否则我将无法获得

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

再次将其删除时,缺少权限再次发生。

我应该怎么做

整个代码:

<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> ```


  

1 个答案:

答案 0 :(得分:0)

这可能是的重复线程 firestore: PERMISSION_DENIED: Missing or insufficient permissions,至少这是我获得此问题帮助的地方。

以正确的方式设置规则后,错误将消失。我在类星体Firebase示例应用程序中也遇到了同样的问题。

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

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

基本上是线

allow read, write: if false;

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

allow read, write: if request.auth != null;

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

allow read, write: if false;