angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

AngularFireAuth doesn't immediately redirect after login

Open albertososa-es opened this issue 9 years ago • 7 comments

Version info

Angular: 2.0.0-beta.11

Firebase: 4.4.0

AngularFire: 4.0.0-RC2

Other (e.g. Ionic/Cordova, Node, browser, operating system): Chrome 61.0.3163.100 64-bits

How to reproduce these conditions

Steps to set up and reproduce

import { Injectable } from '@angular/core';
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';
import { Router } from '@angular/router';
import { Observable } from 'rxjs/Observable';

@Injectable()
export class AuthService {

  public user: firebase.User;
  public authState$: Observable<firebase.User>;

  constructor(private afAuth: AngularFireAuth, private router: Router) {
    this.user = null;
    this.authState$ = afAuth.authState;
    this.authState$.subscribe( (user: firebase.User) => {
      if (user !== null) {
        this.user = user;
        this.router.navigate(['dashboard']);
      }
    } );
  }

  loginWithGoogle() {
    this.afAuth.auth.signInWithRedirect(new firebase.auth.GoogleAuthProvider());
  }
  loginWithFacebook() {
    this.afAuth.auth.signInWithRedirect(new firebase.auth.FacebookAuthProvider());
  }
  loginWithTwitter() {
    this.afAuth.auth.signInWithRedirect(new firebase.auth.TwitterAuthProvider());
  }
  loginWithGitHub() {
    this.afAuth.auth.signInWithRedirect(new firebase.auth.GithubAuthProvider());
  }

  logout() {
    this.afAuth.auth.signOut().then( success => {
      this.router.navigate(['login']);
    });
  }
  isLoggedIn(): boolean {
    return this.user !== null;
  }
}

Expected behavior

When the user make a login with any of the providers, the AuthService immediately redirects them to the dashboard view.

Actual behavior

When the user make a login with any of the providers trought redirect method, the application shows the login page again and after few seconds (5-7") is redirected to the dashboard view.

Notes

Sorry for my english :(

albertososa-es avatar Oct 02 '17 22:10 albertososa-es

@albertososa101 Can you make stackblitz for this? It will be much easier to debug.

davideast avatar Oct 05 '17 03:10 davideast

@davideast I tried it, but Stackblitz uses Angular 4 and I have some errors trying to migrate my code. Clone my repositorie and try it please.

albertososa-es avatar Oct 05 '17 15:10 albertososa-es

@davideast Hi! Debugging my AuthService, the promise returned in signInWithRedirect is never reached (I added .then() and .catch()). With signInWithPopup all is ok.

albertososa-es avatar Oct 08 '17 14:10 albertososa-es

Having the same issue

elvnthaus avatar Oct 16 '17 22:10 elvnthaus

Hmmm, sounds like an issue with the Firebase JS SDK then. Thanks for investigating further. Want to open up an issue there and report back the number? We'll close this out, since it's not exclusively an angularfire issue once it's been accepted. Sound good?

jamesdaniels avatar Oct 16 '17 22:10 jamesdaniels

@elvnthaus @jamesdaniels @davideast I just opened up an issue there. The promise is never reached with redirect method. I put there a better version of the code: https://github.com/firebase/firebase-js-sdk/issues/266

Thanks!

albertososa-es avatar Oct 26 '17 11:10 albertososa-es

@davideast Hi! Debugging my AuthService, the promise returned in signInWithRedirect is never reached (I added .then() and .catch()). With signInWithPopup all is ok.

Follow this for signInWithRedirect() https://firebase.google.com/docs/auth/web/google-signin

warrendodsworth avatar May 25 '21 10:05 warrendodsworth