You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 12:28:13