【发布时间】:2020-05-17 16:57:45
【问题描述】:
我正在使用 firebase 创建一个应用程序。加载任何页面时,我正在通过以下代码检查身份验证。当我从登录页面调用 isAuthenticated 时,即使用户已经登录并且持久性为 LOCAL(https://firebase.google.com/docs/auth/web/auth-state-persistence),它也会返回 false,返回 false 后会执行内部函数。
身份验证.ts
import {auth} from "../firebase";
export function isAuthenticated() {
console.log("Started!");
auth.onAuthStateChanged(function(user) : boolean {
console.log("Coming inside authentication");
if (user) {
console.log('User signed in - auth success! ', user.email);
return true;
} else {
console.log('User not signed in - auth failed! ');
return false;
}
});
console.log("Something wrong, coming here!");
return false;
};
即使在内部 onAuthStateChanged 函数运行之前,我也会变得错误。请看屏幕截图。
如何确保我总是得到内部函数的返回值。
【问题讨论】:
标签: javascript reactjs firebase firebase-authentication