Issue
I'm trying to impliment auth with persistance in angularfire with this code:
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.';
}
}
}
However, i always get this error, no matter the placement of the setPersistence
method:
Class constructor BrowserLocalPersistence cannot be invoked without 'new'
I followed the docs (https://firebase.google.com/docs/auth/web/auth-state-persistence) to the T; what am i doing wrong?
I am using Angular 13, Angularfire 7 and Firebase 9.
Solution
From the documentation on persisting auth state persistence in the JavaScript/web SDK:
For a web application, the default behavior is to persist a user's session even after the user closes the browser.
I strongly recommend only calling setPersistence
if you know you have a specific use-case that requires it. On most browser Firebase will already persist the auth state between reloads, without calling setPersistence
.
Answered By - Frank van Puffelen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.