gpt4 book ai didi

reactjs - Firebase 错误 : Failed to get document because the client is offline

转载 作者:行者123 更新时间:2023-12-03 16:11:11 26 4
gpt4 key购买 nike

我正在使用 React 16.13.1

我正在尝试从“列表”集合中获取文档。
如果我注释掉第 15 到 24 行并取消注释第 25 行,它将起作用。

但是,由于它是我收到此错误:
“FirebaseError:无法获取文档,因为客户端离线。”

传递给 getDoc() 的参数第 24 行与第 25 行相同。

有谁知道为什么会发生这种情况以及我如何获得 getDoc()使用第 18 行时的功能?

更新:我注意到我可以毫无错误地调用数据库,但只有在登录后我才会收到错误“FirebaseError:由于客户端离线而无法获取文档”

1.   import React, { useState, useEffect } from 'react'
2. import { Redirect } from 'react-router-dom'
3. import Firebase from '../../services/Firebase/firebase'
4. import useStyles from './styles.js'
5.
6. const Login = ({ currentUser, setCurrentUser }) => {
7. const [username, setUsername] = useState('')
8. const [password, setPassword] = useState('')
9. const [error, setError] = useState(null)
10.
11. const classes = useStyles()
12.
13. const handleForm = async e => {
14. e.preventDefault()
15. let email = username + '@site.com'
16. let document
17. try {
18. document = await Firebase.doSignInWithEmailAndPassword(email, password)
19. } catch (err) {
20. setError('Sorry, there was an issue with your account. Please try again later.')
21. }
22. const { user } = document
23. console.log(user.uid)
24. getDoc(user.uid)
25. // getDoc('GeAT8UytRYSax49VNwSYAzFrp7t1')
26. }
27.
28. const getDoc = async (uid) => {
29. try {
30. const list = await Firebase.database.collection('List').doc(uid).get()
31. console.log(list)
32. } catch(err){
33. console.log(err)
34. }
35. }
36.
37. return (
38. <>
39. {/* Some HTML */}
40. </>
41. )
42. }
43.
44. export default Login

最佳答案

每当我的控制台在开发模式下在 chrome 中打开时,我都会遇到同样的问题。自从更新到 火力基地 7.15.1 我没有遇到过这个问题。

关于reactjs - Firebase 错误 : Failed to get document because the client is offline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62275068/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com