File

src/providers/auth-service.ts

Index

Properties
Methods

Constructor

constructor(config: Config, storage: Storage, userService: UserService)
Parameters :
Name Type Optional Description
config Config
storage Storage
userService UserService

Methods

delete
delete()
Returns : void
doLoginFirebase
doLoginFirebase(email: string, password: string)
Parameters :
Name Type Optional Description
email string
password string
Returns : any
getUser
getUser()
Returns : firebase.User
logoutUser
logoutUser()
Returns : any
register
register(email: string, password: string, firstname: string, lastname: string)
Parameters :
Name Type Optional Description
email string
password string
firstname string
lastname string
Returns : any
resetPassword
resetPassword(email: string)
Parameters :
Name Type Optional Description
email string
Returns : any

Properties

Public fireAuth
fireAuth: firebase.auth.Auth
Type : firebase.auth.Auth
tenant
tenant: string
Type : string
Public token
token: any
Type : any
Public urlNodeFirebase
urlNodeFirebase: string
Type : string
Public userProfile
userProfile: firebase.database.Reference
Type : firebase.database.Reference
import { Injectable } from '@angular/core';
import { Config } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import 'rxjs/add/operator/map';

import * as firebase from 'firebase/app';


// singlenton
import { UserService } from '../providers/user/user';

/*
  Generated class for the AuthService provider.

  See https://angular.io/docs/ts/latest/guide/dependency-injection.html
  for more info on providers and Angular 2 DI.
*/
@Injectable()
/**
 * DESC PROVIDER
 */
export class AuthService {

  tenant: string;
  public token: any;
  public fireAuth: firebase.auth.Auth;
  public userProfile: firebase.database.Reference;
  public urlNodeFirebase: string;

  constructor(
    //private afAuth: AngularFireAuth, 
    private config: Config, 
    private storage: Storage,
    private userService:UserService
  ) {
    console.log('Hello AuthService Provider');
    // recupero tenant
    // console.log('ionViewDidLoad First');
    // this.userProvider.log(); // log First singleton data
    // this.userProvider.set("First singleton data")

    let appConfig = config.get("appConfig");
    this.tenant = appConfig.tenant;

    this.fireAuth = firebase.auth();
    this.urlNodeFirebase = '/apps/'+this.tenant+'/contacts/';
    this.userProfile = firebase.database().ref(this.urlNodeFirebase);
    //this.afAuth.authState.subscribe();

    // this.afAuth.authState.subscribe((user: firebase.User) => {
    //   this.currentUser = user;
    // });
  }
  
  //Start Firebase Auth//

  // GetUser
  getUser(): firebase.User {
    return this.fireAuth.currentUser;
  }
 

  // Create User Anonymous
  // createAnonymousUser(): firebase.Promise<any> {
  //   return this.fireAuth.signInAnonymously();
  // }

  // Login with Email
  doLoginFirebase(email: string, password: string): any {
    return this.fireAuth.signInWithEmailAndPassword(email, password)
    // .then(res => {
    //   console.log("signInWithEmailAndPassword::: ",res);
    // });
  }


  // Signin with Facebook
  // signInWithFacebook(): any {
  //   return this.afAuth.auth.signInWithPopup(new firebase.auth.FacebookAuthProvider())
  //   .then(res => console.log(res));
  // }


  // Register User with Email
  register(email: string, password: string, firstname: string, lastname: string): any {
    return this.fireAuth.createUserWithEmailAndPassword(email, password); 
  }

  // delete account
  delete(){
    var user = firebase.auth().currentUser;
    user.delete().then(function() {
      // User deleted.
      console.log("delete OK ");
    }).catch(function(error) {
      // An error happened.
      console.log("delete with error: ",error);
    });
  }

  // Reset Password
  resetPassword(email: string): any {
    return this.fireAuth.sendPasswordResetEmail(email);
  }
  
  logoutUser() {
    return firebase.auth().signOut()
    //return this.afAuth.auth.signOut();
    // .then((res) => {
    //   console.log("logout1",res);
    //   console.log("logout2", this.getUser());
    // })
    // .catch(function(error) {
    //   console.log("logout failed: " + error.message)
    // });
  }
  //End Firebase Auth//
}

results matching ""

    No results matching ""