Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import fb from 'firebase';
- import { User } from '../models/user';
- export class AuthService {
- private userId : string;
- private user : User;
- signUp(email: string, password: string){
- return fb.auth().createUserWithEmailAndPassword(email, password);
- }
- signIn(email: string, password: string){
- var user;
- return fb.auth().signInWithEmailAndPassword(email, password)
- .then(data => {
- this.userId = data.uid;
- this.setUser(this.userId);
- })
- .catch(error => console.log(error));
- }
- registerUser(userId: string, nome: string, email:string, role: string){
- return fb.database().ref('users').child(userId).set({
- username: nome,
- email: email,
- tipo_usuario : role
- });
- }
- setUser(userId : string){
- let userRef = fb.database().ref('users').child(userId);
- userRef.on('value', snapshot => this.user = snapshot.val());
- }
- getUser(){
- return this.user;
- }
- getUserId(){
- return this.userId;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement