import { AngularFire , AuthProviders , AuthMethods , FirebaseAuthState } from "angularfire2" ; import { Injectable } from "@angular/core" ; import { BehaviorSubject , Observable } from "rxjs" ; import { Router } from "@angular/router" ; @ Injectable ( ) export class AuthService { private behaviorSubject : BehaviorSubject < FirebaseAuthState > = new BehaviorSubject < FirebaseAuthState > ( null ) ; constructor ( private af , private router ) { this . af . auth . subscribe ( authState => { this . behaviorSubject . next ( authState ) ; } ) ; } loginStateChange ( ) { return this . behaviorSubject . asObservable ( ) ; } loginWithGithub ( ) { this . af . auth . login ( { provider : AuthProviders . Github , method : AuthMethods . Popup , } ) . then ( ( ) => { location . reload ( ) ; } ) ; } getSession ( ) { return this . af . auth ; } logout ( ) { this . af . auth . logout ( ) . then ( ( ) => { location . href = '/posts' ; } ) ; } }