I\'m trying to build an AuthGuard for Angular 2 routes using Firebase Auth.
This is the AuthGuard Service:
import { Injectable } from \'@
For newer versions of AngularFire, you have to use authState instead:
@Injectable()
export class AuthGuard implements CanActivate {
constructor(
private afAuth: AngularFireAuth,
private router: Router
) {}
canActivate(): Observable {
return this.afAuth.authState
.take(1)
.map(authState => !!authState)
.do(auth => !auth ? this.router.navigate(['/login']) : true);
}
}
Don't forget to import take, map and do from rxjs/add/operator.