Advertisement
Guest User

Untitled

a guest
Apr 15th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import fb from 'firebase';
  2.  
  3. import { User } from '../models/user';
  4.  
  5. export class AuthService {
  6.  
  7. private userId : string;
  8. private user : User;
  9.  
  10. signUp(email: string, password: string){
  11. return fb.auth().createUserWithEmailAndPassword(email, password);
  12. }
  13.  
  14. signIn(email: string, password: string){
  15. var user;
  16. return fb.auth().signInWithEmailAndPassword(email, password)
  17. .then(data => {
  18. this.userId = data.uid;
  19. this.setUser(this.userId);
  20. })
  21. .catch(error => console.log(error));
  22. }
  23.  
  24. registerUser(userId: string, nome: string, email:string, role: string){
  25. return fb.database().ref('users').child(userId).set({
  26. username: nome,
  27. email: email,
  28. tipo_usuario : role
  29. });
  30.  
  31. }
  32.  
  33. setUser(userId : string){
  34.  
  35. let userRef = fb.database().ref('users').child(userId);
  36. userRef.on('value', snapshot => this.user = snapshot.val());
  37. }
  38.  
  39. getUser(){
  40. return this.user;
  41. }
  42.  
  43. getUserId(){
  44. return this.userId;
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement