### File

`modules/auth-service/src/auth.service.ts`

### Description

Service that provide user data and methods to work with auth

### Constructor

`constructor(dal: any, sessionFlow: any)`

### Methods

logout
`logout()`
Logout method Returns: `void`

register
`register(registerForm: any)`

Register user

Parameters :

- registerForm

Returns: `void`

userData

login
`login(email: any, password: any)`

Login with email and password

Parameters :

- email

  user email

- password

  user password

Returns: `void`

user data

resetPassword
`resetPassword(email: any)`

Reset user password

Parameters :

- email

  user email

Returns: `void`

Promise containing null

### Properties

userData
`userData: `{}` </bcode>`
User data

    import { SessionFlow } from '@nodeart/session-flow';
    import {Injectable} 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(private dal: DbAbstractionLayer, private sessionFlow: SessionFlow){
        this.dal.getAuth().onAuthStateChanged(authData => {
          if(authData === null){
            this.sessionFlow.userId = 'guest';
            this.userData = {};
          }
          if(authData){
            let uid = authData.uid;
            this.userData = {};
            this.dal.getUserData(uid).on('value', data => {
              if(data.val()){
                let userData = data.val()[0]['_source'];
                this.sessionFlow.userId = data.val()[0]['_id'];
                this.userData = userData;
              }
            });
          }
        });
      }

      /**
       * Logout method
       */
      logout(){
        return this.dal.logout();
      }

      /**
       * Register user
       * @param registerForm
       * @returns {Object} userData
       */
      register(registerForm){
        return this.dal.registerUser(registerForm);
      }

      /**
       * Login with email and password
       * @param email user email
       * @param password user password
       *
       * @returns user data
       */
      login(email, password){
        return this.dal.loginEmail(email, password);
      }

      /**
       * Reset user password
       * @param email user email
       * @returns Promise containing null
       */
      resetPassword(email) {
        return this.dal.resetPassword(email);
      }
    }

# results matching ""

# No results matching ""