-
-
Save geykel/554928abdd8ffb7746532d0c232b041b to your computer and use it in GitHub Desktop.
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 { 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