Skip to content

Instantly share code, notes, and snippets.

@geykel

geykel/auth-service2.ts Secret

Created Jun 27, 2017
Embed
What would you like to do?
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
You can’t perform that action at this time.