首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react-native-firebase firestore权限被拒绝

react-native-firebase firestore权限被拒绝
EN

Stack Overflow用户
提问于 2017-10-26 14:56:30
回答 1查看 1.9K关注 0票数 1

我在这里尝试做的实际上是从我的firestore中读取数据。我遵循了RNF文档中的所有安装,但当我尝试从我的文档中获取数据或者只是引用到firestore集合中时,出现了一个错误:

我试着改变规则(因为我认为这是涉及到的规则),但没有成功。下面是我的数据库结构:

下面是我的代码:

代码语言:javascript
复制
import React, { Component } from 'react';
import {View, Text, FlatList, Image, StyleSheet, Button, TouchableHighlight} from 'react-native';
import firebase from 'react-native-firebase';
import MainApp from './src/screen/test';

export default class App extends Component<{}> {
  constructor(){
    super();
    this.itemsRef = this.getRef('questions');
    this.state = {
      items:[],
      loading:true,
    };

  }

  setModalVisible(visible){
    this.setState(modalVisible:visible);
  }
  getRef(location){
    return firebase.firestore().collection('chat');
  }
  componentWillMount(){
    this.getItems(this.itemsRef);
  }
  componentDidMount(){
    //this.getItems(this.itemsRef);
  }
  getItems(itemsRef){
    firebase.firestore().collection('Users').get().then((snap)=>{
      let items =[];
      alert(snap);
      snap.forEach((childSnap)=>{
        items.push({
        title:childSnap.val().question,
        _key:childSnap.key
        });
        alert(childSnap.key)
      })
      this.setState({
        items,
        loading:false
      })
    })
  }
  pressRow(item){
    alert(item);
  }
  renderRow(item){
    return(
      <TouchableHighLight onPress={()=>{
        this.pressRow(item)
      }}>
      <View>
      <Text>{item.title}</Text>
      </View>
      </TouchableHighLight>
    )
  }
  addItem(){

  }
  render() {
    if (this.state.loading) {
    return null; // or render a loading icon
    }
    return (
      <View style={{ flex: 1 }}>
      <FlatList
        data={this.state.items}
      />
      <Button
          title={'Add TODO'}
          onPress={() => console.log()}
      />
  </View>
    );
  }
}

如何修复此错误?

EN

回答 1

Stack Overflow用户

发布于 2017-10-26 16:42:56

firestore的默认设置是禁用访问。

因此,如果您没有设置访问规则,则无法获取数据。

将它们更改为以下内容-但仅用于测试:

service cloud.firestore { match /databases/{database}/documents { // Match all documents, recursively, with a wildcard and the "=**" recursive modifier match /{document=**} { allow read, write; } } }

然后,在它工作之后-阅读更多关于here的内容。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46947671

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档