调用firestore collection()在博览会上不起作用 [英] Call to firestore collection() not working on expo

查看:25
本文介绍了调用firestore collection()在博览会上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用:用EXPO响应Native

Using: React Native with expo

react-redux:5.0.6

react-redux: 5.0.6

redux:3.7.2

redux: 3.7.2

firebase:4.9.0

firebase: 4.9.0

(请参阅以下修复程序:降级为Firebase 4.6.2)

(See fix below: Downgraded to firebase 4.6.2)

更新:由于怀疑redux在firebase上不能很好地工作,因此这是一个更长的问题.但这似乎并非如此.只保留相关部分

UPDATE: This was a longer question based on the suspicion that redux wasn't working nicely with firebase. But that doesn't seem to be the case. Only keeping the relevant parts

这是与Redux挂钩的动作创建者.在此处使用 firebase.auth().signInWithEmailAndPassword()时,一切正常.

This is an action creator hooked up with redux. When using firebase.auth().signInWithEmailAndPassword() here, everything works fine.

action.js

import firebase from 'firebase'
import 'firebase/firestore'

export const dataFetch = () => {
    return (dispatch) => {
        firebase.auth().signInWithEmailAndPassword('a@b.com', 'passw')      
        .then(
            (result => dispatch({ type: 'DATA_FETCH_SUCCESS', payload: result })),
            (() => alert("got here"))
        )
        .catch((err) => alert(err))
    }
};

但是当使用 firebase.firestore().collection(...).get()时,执行不会进入 then()部分中-可以里面没有东西.

But when using firebase.firestore().collection(...).get(), execution doesn't go inside the then() part - can't log anything inside it.

import firebase from 'firebase'
import 'firebase/firestore'

export const dataFetch = () => {
    return (dispatch) => {
        firebase.firestore().collection('MyCollection').get()
        .then(
            (result => dispatch({ type: 'DATA_FETCH_SUCCESS', payload: result })),
            (() => alert("got here"))
        )
        .catch((err) => alert(err))
    }
};

可能是什么问题?是否有通过收集路径的特定方法?Firebase配置不正确吗?我仔细检查了所有看起来正确的内容.我正在使用Web应用程序的配置.有专门针对Firestore的东西可能会丢失吗?

What could be the issue? Is there a specific way to pass the collection path? Could the firebase config be incorrect? I double-checked everything at it looks right. I'm using the config for a web app. Is there something specific to firestore that could be missing?

我的firebase配置中有以下键:

I have the following keys in my firebase config:

apiKey: '',           // Auth / General use
authDomain: '',       // Auth with popup/redirect
databaseURL: '',      // Realtime Database
storageBucket: '',    // Storage
messagingSenderId: '',// Cloud Messaging
projectId: '',        // Firestore

推荐答案

好吧,所以经过大量搜索后发现,这是与Firestore无法与EXPO配合使用的问题!(问题标题的更新反映了这一点.)

Ok, so searched around a lot and found that it is a problem related to firestore not working with expo! (Updated title of the question to reflect this).

对此没有稳定的解决方法,但是其他人已经遇到了此问题,并且这里有一种解决方法,请检查Igor的回答:在响应本机应用程序中(通过Expo)使用Firestore权限-request.auth始终为空

There is no stable fix for this but others have faced this issue and there is a workaround here, check answer by Igor: In react native app (through Expo) using firestore permissions - request.auth is always null

问题在React Native中,并在这里进行了讨论: https://github.com/firebase/firebase-js-sdk/issues/283#issuecomment-345815579

The issue is in React Native and has been discussed here: https://github.com/firebase/firebase-js-sdk/issues/283#issuecomment-345815579

希望它将很快成为正式版本.

Hopefully it will make it to the official builds soon.

仅供参考,我降级为Firebase 4.6.2,并替换了上面链接中提到的index.js文件,现在一切正常.

FYI, I downgraded to firebase 4.6.2 and replaced the index.js file mentioned in the link above and things work perfectly now.

这篇关于调用firestore collection()在博览会上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆