AngularFire Auth Persistence cannot be invoked without 'new'

Discussão em 'Angular' iniciado por Harry Allen, Fevereiro 16, 2025.

  1. Harry Allen

    Harry Allen Guest

    I'm trying to implement auth with persistence 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.

    Continue reading...

Compartilhe esta Página