Skip to content

Instantly share code, notes, and snippets.

@iBasit
Created July 20, 2017 12:51
Show Gist options
  • Save iBasit/12e33d6ccfd655f27d2e97662eb60ee5 to your computer and use it in GitHub Desktop.
Save iBasit/12e33d6ccfd655f27d2e97662eb60ee5 to your computer and use it in GitHub Desktop.
firebase login with custom token example
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