我正在尝试使用以下代码在 AngularFire 中实现持久性身份验证:
constructor(private auth: Auth, private router: Router) {
if (auth.currentUser) this.router.navigate(this.redirect);
}
async loginWithGoogle() {
const provider = new GoogleAuthProvider();
try {
await setPersistence(this.auth, browserLocalPersistence);
await signInWithPopup(this.auth, provider);
this.message = 'Sign in successful';
await this.router.navigate(this.redirect);
} catch (error: any) {
console.error(error);
if (error.code) {
this.message = `${error.code}: ${error.message}`;
} else {
this.message = 'There was a problem signing in. Please try again.';
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,无论方法的位置如何,我总是收到此错误setPersistence:
Class constructor BrowserLocalPersistence cannot be invoked without 'new'
Run Code Online (Sandbox Code Playgroud)
我按照文档(https://firebase.google.com/docs/auth/web/auth-state-persistence …
firebase firebase-authentication angularfire2 angular rxfire