import { Injectable, FactoryProvider } from '@angular/core'; import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs'; import { AuthService as MawAuthService } from './maw-auth.service'; import { environment } from '../../environments/environment'; const bomConfig = environment.bomConfig; @Injectable() export class AuthService { constructor(private http: HttpClient) {} /** * Login and authenticate user then set api token on success * @param email * @param password */ public login(username: string, password: string): Observable { const body = new HttpParams() .set('username', username) .set('password', password); const headers = new HttpHeaders().set( 'Content-Type', 'application/x-www-form-urlencoded' ); return this.http.post('https://qa.arrow.com/login/loginlite', body, { headers }); } } export function authFactory(http: HttpClient) { if (bomConfig.target === 'myarrow') { return new MawAuthService(http); } return new AuthService(http); } export const AuthProvider: FactoryProvider = { provide: AuthService, useFactory: authFactory, deps: [HttpClient] };