每当挂载组件时,都会调用onAuthStateChange(setCurrentUser),其中传入了一个设置currentUser状态的函数。然后,Firebase根据用户是否登录返回一个身份验证对象,我使用它来设置currentUser的状态,并使用createUserDocument()将数据保存在firestore中。function onAuthStateChange(callback) { if (userAu
通过使用上下文和firebase,我尝试使用onAuthStateChange在应用程序中设置用户。收到用户后,useEffect再次运行并返回null。import React, { createContext, useState, useEffect } from 'react';// the context
const Au
我将我的应用程序的Firebase版本从3.5.0升级到4.1.3,并注意到在用户验证电子邮件地址后首次成功登录后,不再调用onAuthStateChange回调函数。以下是我代码的相关部分:firebase.auth().onAuthStateChanged(onAuthStateChange);function onAuthStateChange(user) {
console.log(user); // Not appearing in console
我现在创建的代码正在工作,但我认为它在某种程度上是次优的,就我所理解的许多数据库读取而言,"onAuthStateChange“可以被理解为一个useEffect钩子,每当用户身份验证状态发生变化(登录import { createContext } from "react/cjs/react.production.min";import { doc, ge