Firebase getRedirectResult() doesn't resolve onInit (Angular)

Discussão em 'Angular' iniciado por Peter W, Janeiro 2, 2025.

  1. Peter W

    Peter W Guest

    In my Angular project I am trying to implement Firebase loginWithRedirect() via Google Sign-In. Strange thing is, sometimes the getRedirectResult() method does not return anything after redirecting from successful Google Login. Even more strange: on the mobile phone it never resolves. In those cases, all I receive is: { "credential": null, "user": null }

    My login method:

    async onLogin(isGoogleLogin) {
    const loading = await this.loadingController.create();
    await loading.present();
    let user;
    if (isGoogleLogin) {
    await this.authService.loginWithGoogle();
    // The upper method just calls: await this.angularFireAuth.signInWithRedirect(new GoogleAuthProvider());
    } else {
    user = await this.authService.login(this.credentials.value);
    }
    await loading.dismiss();

    if (user) {
    this.buildNavPathAndNav();
    } else {
    this.utilService.showErrorToast('Login error', 'Login failed, please try again');
    }
    }


    My onInit function on the login screen:

    async ngOnInit() {
    // Get user if logged in via redirect (e.g. google)
    const user = await this.authService.getRedirectLoginResult();

    // Navigate to home screen
    if (user) { this.buildNavPathAndNav(); };
    }


    My getRedirectLoginResult function:

    async getRedirectLoginResult() {
    const loading = await this.loadingController.create();
    await loading.present();

    const userObj = await this.afAuth.getRedirectResult();
    if (!userObj.user) {
    await loading.dismiss();
    return;
    };

    await this.dataService.setCurrentUser(userObj.user);
    await loading.dismiss();
    return userObj.user;
    }


    I would really appreciate some help. Thanks!

    Continue reading...

Compartilhe esta Página