Checking if user is still authenticated in angularfire2

You can use the prebuilt Route users with AngularFire guards

AngularFireAuthGuard provides a prebuilt canActivate Router Guard using AngularFireAuth.

You can customize the behavior of this AngularFireAuthGuard by passing an RXJS pipe through the route data's authGuardPipe. You can learn more here.


AngularFire2 is currently undergoing some refactoring and significant portions of its authentication API are going to be removed in favour of using the Firebase Web API in conjunction with AngularFire2. There is more information in this issue.

The observable that you have used will remain in AngularFire2 and you can subscribe to it to receive notifications of changes in the authentication state.

However, if all you are interested in is determining whether or not there is a currently authenticated user, there is a currentUser property in the Firebase Web API that will tell you that:

import * as firebase from "firebase";
...
console.log(firebase.auth().currentUser);