【发布时间】:2020-02-04 07:34:34
【问题描述】:
这是我在个人资料页面上的代码,当我从 AuthService 的登录方法重定向时,这第一次运行良好
const user = firebase.auth().currentUser;
if (user != null) {
this.name = user.displayName;
this.uid = user.uid;
} else {
this.name = "Unknown";
}
但是,如果我刷新页面或转到任何其他页面并返回此个人资料页面,currentUser 将变为 null。
这是我的身份验证服务代码。
import * as firebase from "firebase/app";
import { auth } from "firebase/app";
async googleSignin() {
firebase
.auth()
.setPersistence(firebase.auth.Auth.Persistence.LOCAL)
.then(async () => {
const provider = new auth.GoogleAuthProvider();
const credential = await this.afAuth.auth.signInWithPopup(provider);
this.updateUserData(credential.user);
this.router.navigate(["/profile"]);
return;
});
}
为什么我失去了 currentUser?我什至还添加了 Persistence.LOCAL。
【问题讨论】:
标签: javascript angular firebase firebase-authentication