AngularFireAuth doesn't immediately redirect after login
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 :(
@albertososa101 Can you make stackblitz for this? It will be much easier to debug.
@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.
@davideast Hi! Debugging my AuthService, the promise returned in signInWithRedirect is never reached (I added .then() and .catch()). With signInWithPopup all is ok.
Having the same issue
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?
@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!
@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