FirebaseError:权限缺失或不足。 -类星体和火力基地

Posted

技术标签:

【中文标题】FirebaseError:权限缺失或不足。 -类星体和火力基地【英文标题】:FirebaseError: Missing or insufficient permissions. -quasar & Firebase 【发布时间】:2020-10-12 14:53:39 【问题描述】:

我正在使用 Quasar 和 Firebase

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

error

脚本:

// 从火力基地获取 常量路径 = "/newpage"; this.$auth.onAuthStateChanged(authUser => 如果(身份验证用户) this.$bind('userz', this.$db.collection('users')); this.$db.collection('users').doc(authUser.uid).get() .then(快照 => const userData = 快照.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'));```

发生缺少权限

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

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

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】:

这可能是一个重复的线程 firestore: PERMISSION_DENIED: Missing or insufficient permissions,至少这是我解决这个问题的地方。

正确设置规则后,错误就会消失。我对 quasar 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;

【讨论】:

以上是关于FirebaseError:权限缺失或不足。 -类星体和火力基地的主要内容,如果未能解决你的问题,请参考以下文章

firebase 错误:FirebaseError:缺少权限或权限不足

任何人都知道为啥我会收到“快照侦听器中未捕获的错误:FirebaseError:缺少权限或权限不足”吗?

注销后权限缺失或权限不足错误

Firebase Cloud Functions 无法写入 Firestore 数据库 - 权限缺失或不足

带有 Firebase 的 Angular - 应用检查后权限缺失或不足

Node.js 中的 Firestore 管理员权限缺失或不足