Javascript Firebase Google signInWithRedirect在成功验证时未重定向到指定页面

Javascript Firebase Google signInWithRedirect在成功验证时未重定向到指定页面,javascript,firebase,vue.js,firebase-authentication,vue-router,Javascript,Firebase,Vue.js,Firebase Authentication,Vue Router,以下问题需要一些帮助/解释。我正在为我的项目使用Vue和Firebase 我正在尝试通过调用signInWithRedirect来设置Firebase Google登录。身份验证本身是有效的,但并不是我想要的那样 我需要在进行身份验证后将其重定向到/dashboard,但当前它在短时间加载后重定向回/login页面 我知道我必须使用getRedirectResult,但我不确定如何准确地调用它。如果有人能解释我如何正确编写代码以获得想要的结果,我将不胜感激 .signInWithRedirect

以下问题需要一些帮助/解释。我正在为我的项目使用Vue和Firebase

我正在尝试通过调用signInWithRedirect来设置Firebase Google登录。身份验证本身是有效的,但并不是我想要的那样

我需要在进行身份验证后将其重定向到/dashboard,但当前它在短时间加载后重定向回/login页面

我知道我必须使用getRedirectResult,但我不确定如何准确地调用它。如果有人能解释我如何正确编写代码以获得想要的结果,我将不胜感激

.signInWithRedirect(fb.googleProvider)
.then(credential => {
this.$store.commit("setCurrentUser", credential.user)
fb.usersCollection.doc(credential.user.uid).set({
}).then(() => {
this.$store.dispatch("fetchUserProfile")
this.updateGmailData()
this.$router.push("/dashboard")
}).catch(err => {
console.log(err)
})
}).catch(err => {
console.log(err);
});
},
我相信我的初始身份验证应该是这样的-

googleLogin() {
fb.auth.signInWithPopup(fb.googleProvider)
}
然后,我应该为getRedirectResult设置函数,该函数应该将路由器推到/dashboard

如何重定向以等待getRedirectResult,以及在获得所需结果后重定向/仪表板

.signInWithRedirect(fb.googleProvider)
.then(credential => {
this.$store.commit("setCurrentUser", credential.user)
fb.usersCollection.doc(credential.user.uid).set({
}).then(() => {
this.$store.dispatch("fetchUserProfile")
this.updateGmailData()
this.$router.push("/dashboard")
}).catch(err => {
console.log(err)
})
}).catch(err => {
console.log(err);
});
},

我不知道如何实施它。

这些方法对我很有效:

googleLogin(){

  this.afAuth.auth.signInWithPopup(new  
  firebase.auth.GoogleAuthProvider()).then(result=>{

     console.log(result)
  }).catch(err=>{
     console.log(err)
  })
}

signInWithRedirect
将重定向回将完成登录的同一页面。然后,您可以使用
getRedirectResult()
onAuthStateChanged
侦听器在用户登录后重定向到仪表板

在登录按钮中,单击处理程序,调用:

// This will redirect to IdP for sign-in.
firebase.auth.signInWithRedirect(fb.googleProvider);
然后在同一页面上,您可以设置侦听器:

firebase.auth().onAuthStateChanged((user) => {
  if (user) {
    // User signed in, you can get redirect result here if needed.
    // ...
    this.$router.push("/dashboard");
    // ....
  } else {
    // Show sign in screen with button above.
  }
});

这与signInWithRedirect无关