Skip to content

Instantly share code, notes, and snippets.

@geykel
Created June 27, 2017 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geykel/554928abdd8ffb7746532d0c232b041b to your computer and use it in GitHub Desktop.
Save geykel/554928abdd8ffb7746532d0c232b041b to your computer and use it in GitHub Desktop.
import { Injectable } from '@angular/core';
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';
import { UserModel } from '../models/user-model';
@Injectable()
export class AuthService {
user: firebase.User;
constructor(public angularFireAuth: AngularFireAuth) {
angularFireAuth.authState.subscribe((user: firebase.User) => {
this.user = user;
});
}
get authenticated(): boolean {
return this.user != null;
}
signInWithEmailAndPassword(userModel: UserModel): firebase.Promise<any> {
return this.angularFireAuth.auth.signInWithEmailAndPassword(userModel.email, userModel.password);
}
createUserWithEmailAndPassword(userModel: UserModel): firebase.Promise<any> {
return this.angularFireAuth.auth.createUserWithEmailAndPassword(userModel.email, userModel.password);
}
signInWithFacebook(accessToken: string): firebase.Promise<any> {
const facebookCredential = firebase.auth.FacebookAuthProvider.credential(accessToken);
return this.angularFireAuth.auth.signInWithCredential(facebookCredential);
}
signInWithPopup(): firebase.Promise<any> {
return this.angularFireAuth.auth.signInWithPopup(new firebase.auth.FacebookAuthProvider());
}
signOut(): firebase.Promise<any> {
return this.angularFireAuth.auth.signOut();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment