sách gpt4 ăn đã đi

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

In lại Tác giả: trợ lý lỗi 更新时间:2023-10-25 13:12:31 29 4
mua khóa gpt4 giày 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()?


Thêm câu trả lời
Khuyến nghị câu trả lời tuyệt vời

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以查看新数据。


Thêm câu trả lời
29 4 0
trợ lý lỗi
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress