import { SessionFlow } from '@nodeart/session-flow' ; import { Injectable , NgZone } from "@angular/core" ; import { DbAbstractionLayer } from "@nodeart/dal" ; /**
 * Service that provide user data and methods to work with auth
 */ @ Injectable ( ) export class AuthService { /**
     * User data
     */ userData = { } ; constructor ( protected dal , protected sessionFlow , protected zone ) { this . dal . getAuth ( ) . onAuthStateChanged ( authData => { if ( authData === null ) { this . sessionFlow . userId = 'guest' ; this . userData = { } ; this . dal . initializeBasketHistory ( sessionFlow . deviceId ) ; } if ( authData ) { let uid = authData . uid ; this . userData = { } ; this . userData [ 'uid' ] = uid ; this . dal . getUserData ( uid ) . subscribe ( data => { if ( data . val ( ) ) { let userData = data . val ( ) [ 0 ] [ '_source' ] ; userData . userId = data . val ( ) [ 0 ] [ '_id' ] ; this . sessionFlow . userId = data . val ( ) [ 0 ] [ '_id' ] ; this . dal . initializeBasketHistory ( userData . userId ) ; this . zone . run ( ( ) => { this . userData = userData ; } ) ; } } ) ; } } ) ; } /**
     * Logout method
     */ logout ( ) { return this . dal . logout ( ) ; } param registerForm returns { Object } register ( registerForm ) { return this . dal . registerUser ( registerForm ) ; } param email param password returns login ( email , password ) { return this . dal . loginEmail ( email , password ) ; } param email returns resetPassword ( email ) { return this . dal . resetPassword ( email ) ; } }