Javascript Firebase身份验证检测用户是否来自重定向登录
当使用Firebase身份验证的方法时,是否有方法检测我们是否应该期望结果(或者用户是否来自重定向登录) 在运行此方法和发生成功/错误回调时会有延迟。我希望尽快显示一些加载状态,并且在文档中看不到任何方法,如Javascript Firebase身份验证检测用户是否来自重定向登录,javascript,firebase,firebase-authentication,Javascript,Firebase,Firebase Authentication,当使用Firebase身份验证的方法时,是否有方法检测我们是否应该期望结果(或者用户是否来自重定向登录) 在运行此方法和发生成功/错误回调时会有延迟。我希望尽快显示一些加载状态,并且在文档中看不到任何方法,如isRedirectResult 例如,我想要这样的东西(psuedo代码) button.onclick=()=>{ firebase.auth().signInWithRedirect(提供程序); } 如果(isFromRedirectPage){//我该如何做?? button.l
isRedirectResult
例如,我想要这样的东西(psuedo代码)
button.onclick=()=>{
firebase.auth().signInWithRedirect(提供程序);
}
如果(isFromRedirectPage){//我该如何做??
button.loading=true;
等待firebase.auth().getRedirectResult();
button.loading=false;
}否则{
按钮。显示();
}
可能会混淆方法的调用,但我最终还是能够使用firebase.auth().onAuthStateChanged((user)=>{…})来解决这个问题
即使用户未登录,此方法也会调用回调函数,因此我使用它来确定加载状态:
loading = true;
firebase.auth().onAuthStateChanged((user) => {
loading = false;
if (!user) {
// show login button
} else {
// hide login button
}
});