import { Injectable } from '@angular/core' ; import { HttpClient } from '@angular/common/http' ; import { Observable , of } from 'rxjs' ; import { map , catchError } from 'rxjs/operators' ; import { GenericHttpService } from '@app/shared/services/generic-http/generic-http.service' ; export interface HttpServerResponse extends Response { message ? : string ; code ? : number ; token ? : string ; user ? : any ; } @ Injectable ( ) export class AuthService extends GenericHttpService { private readonly _authUrl : string = '/auth' ; private readonly _isAuthUrl : string = '/auth/isauth' ; private readonly _signUpUrl : string = '/auth/signin' ; constructor ( public http ) { super ( http ) ; } /**
     * Methode to deconnect user. Will trigge dellToken()
     */ doLogout ( ) { return this . dellToken ( ) ; } isAuth ( loadUserData = false ) { return super . get ( this . _isAuthUrl + ( loadUserData ? '?loadUserData=true' : '' ) ) . pipe ( map ( res => res || { } ) , catchError ( res => of ( { error : res , message : ( res . error || { } ) . message || res . message || 'Authentication failed!' } ) ) ) ; } param _creds doAuth ( _creds = { email : null , password : null } ) { return super . post ( this . _authUrl , { email : _creds . email , password : _creds . password } ) . pipe ( catchError ( res => of ( { error : res , message : ( res . error || { } ) . message || res . message || 'Login authentication failed!' } ) ) ) ; } doCreateUser ( _payload ) { console . log ( '_payload' , _payload ) ; return super . post ( this . _signUpUrl , _payload ) . pipe ( catchError ( err => of ( { error : err , message : err . message || 'Signup failed!' } ) ) ) ; } /**
     * Methode to remove token from localstorage
     * See doc from `HttpService`
     */ dellToken ( ) { return super . dellToken ( ) ; } }