这是我在个人资料页面上的代码,当我从 AuthService 的登录方法重定向时,这第一次工作正常
const user = firebase.auth().currentUser;
if (user != null) {
this.name = user.displayName;
this.uid = user.uid;
} else {
this.name = "Unknown";
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我刷新页面或转到任何其他页面并返回此个人资料页面,则 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;
});
}
Run Code Online (Sandbox Code Playgroud)
为什么我会丢失 currentUser?我什至还添加了 Persistence.LOCAL。
这可能是一个愚蠢的问题,但我在互联网上没有找到答案。我看到以下 MVC5 和 oAuth 代码
\n\napp.UseFacebookAuthentication\napp.UseGoogleAuthentication();
\n\n但是,我在调试器中的应用程序对象上没有看到任何名为 UseGoogleAuthentication 的方法。我确实在 Katana 代码中的 AppBuilder 上看到了 \xe2\x80\x9cUse\xe2\x80\x9d 方法。那么发生了什么?这个 \xe2\x80\x9capp.UseGoogleAuthentication();\xe2\x80\x9d 神秘方法是从哪里来的?我确信我错过了一些约定,但它是什么?
\n\n提前致谢
\n