Quasar应用中signOut时onAuthStateChanged多次触发(登出时触发5次)的问题求助
Quasar应用中signOut时onAuthStateChanged多次触发(登出时触发5次)的问题求助
各位大佬好,我最近在开发Quasar应用时遇到了一个头疼的问题:每次登录和登出操作时,Firebase的onAuthStateChanged()都会触发多次,尤其是执行登出操作后,从store的signOut() action里触发的次数居然达到了5次!按我的理解,调用signOut()之后,这个状态监听应该只触发一次才对,实在搞不清楚哪里出了问题。
先贴一下我的相关代码:
Store中的signOut action(index.js)
async signOut() { await signOut(auth) .then((res) => { this.user = null; }) .catch((error) => { // An error happened. }); }
Router中的全局前置守卫(router/index.js)
Router.beforeEach(async (to, from, next) => { const authStore = useGenStore(); console.log("router start"); await new Promise((resolve) => { onAuthStateChanged(auth, (user) => { console.log("inituser"); <--- 这里每次都会输出5次! initUser(user) .then(() => resolve(user)) ; }); }); });
我怀疑是不是每次路由跳转的beforeEach里都重新注册了onAuthStateChanged监听,导致监听越积越多?但不太确定怎么验证和修复这个问题,有没有遇到过类似情况的朋友能给点思路?
备注:内容来源于stack exchange,提问作者jdost_26
相关产品推荐
相关产品推荐

