Advertisement
Guest User

Untitled

a guest
Jun 7th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2. import { Observable } from 'rxjs/Observable';
  3. import { AngularFireAuth } from 'angularfire2/auth';
  4. import * as firebase from 'firebase/app';
  5.  
  6. @Injectable()
  7. export class AuthService {
  8. public user : Observable<firebase.User>;
  9. private auth;
  10.  
  11. constructor( public afAuth: AngularFireAuth )
  12. {
  13. this.user = afAuth.authState;
  14. this.auth = firebase.auth();
  15. }
  16.  
  17.  
  18. login() {
  19. this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider());
  20. }
  21.  
  22. logout() {
  23. this.afAuth.auth.signOut();
  24. }
  25.  
  26. register(email:any, password:any)
  27. {
  28. console.log('xx');
  29. console.log(email);
  30. let promise = this.auth.createUserWithEmailAndPassword(email, password);
  31. promise.catch( e => {
  32. console.log(e);
  33. });
  34. this.auth.onAuthStateChanged(firebaseUser =>{
  35. if( firebaseUser )
  36. {
  37. console.log(firebaseUser);
  38. }else{
  39. console.log(firebaseUser);
  40. }
  41. } );
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement