gpt4 book ai didi

auth.onAuthStateChanged not triggering after auth.currentUser.updateProfile in Firebase(在Firebase中的Auth.CurentUser.updateProfile之后,auth.onAuthStateChanged不触发)

转载 作者:bug小助手 更新时间:2023-10-25 13:12:31 29 4
gpt4 key购买 nike



I have a component updating the user's profile pic:

我有一个更新用户个人资料图片的组件:



const Updater = () => {

const updateProfilePic = async (photoURL) => {

await auth.currentUser.updateProfile({ 'photoURL': photoURL });

}

}


I have a second component detecting changes in the user's state:

我有第二个组件检测用户状态的变化:



const StateChangesDetector = () => {

auth.onAuthStateChanged( user => {

if(user)
console.log('User changed state', JSON.stringify(user));

});

}



The problem is that auth.onAuthStateChanged() is not triggering after the execution of updateProfile(). Thus, I'm getting the old user's state and the old profile picture.

问题是,在执行updateProfile()之后,没有触发auth.onAuthStateChanged()。因此,我得到了老用户的状态和旧的个人资料图片。



How can I force to trigger auth.onAuthStateChanged() after updating the user's profile picture?

在更新用户的个人资料图片后,如何强制触发auth.onAuthStateChanged()?


更多回答
优秀答案推荐

Try the reload() function on the currentUser object to get updated information. Note that it's asynchronous and returns a promise. If it doesn't trigger the listener (as it's not really a "state" change, just a refresh of data), I suspect you might have to access the firebase.auth().currentUser again after the returned promise resolves to see new data.

尝试在CurrentUser对象上使用reLoad()函数以获取更新的信息。请注意,它是异步的,并且返回一个承诺。如果它没有触发侦听器(因为它不是真正的“状态”更改,只是数据的刷新),我怀疑您可能需要在返回的承诺解析后再次访问Firebase.auth().CurrentUser以查看新数据。


更多回答

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