Created
July 20, 2017 12:51
-
-
Save iBasit/12e33d6ccfd655f27d2e97662eb60ee5 to your computer and use it in GitHub Desktop.
firebase login with custom token example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Observable } from 'rxjs/Observable'; | |
import { Injectable } from '@angular/core'; | |
import { AngularFireAuth } from 'angularfire2/auth'; | |
// Do not import from 'firebase' as you'll lose the tree shaking benefits | |
import * as firebase from 'firebase/app'; | |
@Injectable() | |
export class AuthService { | |
private currentUser: firebase.User; | |
constructor(public afAuth: AngularFireAuth) { | |
afAuth.authState.subscribe((user: firebase.User) => this.currentUser = user); | |
} | |
get authenticated(): boolean { | |
return this.currentUser !== null; | |
} | |
signInWithFacebook(): firebase.Promise<any> { | |
return this.afAuth.auth.signInWithPopup(new firebase.auth.FacebookAuthProvider()); | |
} | |
signOut(): void { | |
this.afAuth.auth.signOut(); | |
} | |
displayName(): string { | |
if (this.currentUser !== null) { | |
return this.currentUser.facebook.displayName; | |
} else { | |
return ''; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment