注销后会调用Firebase getRedirectResult

时间:2021-05-13 19:41:24

I'm a little confused by some behaviour I'm seeing with Firebase. I never used the old version, but I believe getRedirectResult is new since they joined forces with Google.

我对Firebase的一些行为感到有些困惑。我从未使用旧版本,但我相信getRedirectResult是新的,因为他们与Google合作。

I have a SPA that I am using Vue.js with vue-router, and Firebase for. There is a landing page, and then another view for which users can be logged in, or not. Login is done by redirect. When this second view is loaded, I check getRedirectResult in the vue-router 'activate' hook, and if there is a user, do some other stuff with the user information.

我有一个SPA,我正在使用Vue.js与vue-router和Firebase for。有一个登录页面,然后是另一个用户可以登录或不登录的视图。登录由重定向完成。当加载第二个视图时,我在vue-router'activate'钩子中检查getRedirectResult,如果有用户,则用其他信息做一些其他事情。

The problem proceeds thusly:
1. We are on second page. User logs in. getRedirectResult is called and finds a user. Yay.
2. User logs out. We are back on landing page.
3. We click a button that leads us to second page. getRedirectResult is called and finds the previous user. What?! No!

问题就这样进行了:1。我们在第二页。用户登录。调用getRedirectResult并查找用户。好极了。 2.用户注销。我们回到了登陆页面。 3.我们点击一​​个按钮,将我们引导至第二页。调用getRedirectResult并找到以前的用户。什么?!没有!

I can't find anything on whether I am missing something and need some kind of extra check in place, or to somehow forcibly refresh the page after logout so it forgets that the last user logged in, or if this would be considered a bug. Any assistance would be greatly appreciated!

我无法找到任何关于我是否遗漏某些内容并需要某种额外检查的内容,或者以某种方式在注销后强行刷新页面,因此忘记了最后一个用户登录,或者这是否会被视为错误。任何帮助将不胜感激!

getRedirectResult call on second page in vue component router 'activate' hook:

在vue组件路由器'activate'钩子的第二页上调用getRedirectResult:

    firebase.auth().getRedirectResult()
        .then((result) => {
          return result.user;
        }).then((user) => {
          // Do stuff.
        });
    

Update: Solved by doing a hard page refresh in the logout callback, as follows:

更新:通过在注销回调中执行硬页面刷新来解决,如下所示:

    firebase.auth().signOut()
        .then(() => {window.location.href = '/'});
    

1 个解决方案

#1


0  

Use a flag to detect if getRedirectResult() has been processed. i.e.

使用标志来检测是否已处理getRedirectResult()。即

firebase.auth().getRedirectResult()
  .then((result) => {
    return result.user;
  }).then((user) => {
    if (this.authRedirected)
      return; // Skip

    // Do stuff.

    this.authRedirected = true; // Mark redirected
  });

#1


0  

Use a flag to detect if getRedirectResult() has been processed. i.e.

使用标志来检测是否已处理getRedirectResult()。即

firebase.auth().getRedirectResult()
  .then((result) => {
    return result.user;
  }).then((user) => {
    if (this.authRedirected)
      return; // Skip

    // Do stuff.

    this.authRedirected = true; // Mark redirected
  });