Created
November 18, 2021 16:01
-
-
Save whisher/79ced5a625899f9d8375509e18b5439c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { environment } from '../../../environments/environment'; | |
const apiEndpoint = environment.apiEndpoint; | |
export interface PathsAuthDto { | |
current: string; | |
login: string; | |
signIn: string; | |
} | |
export interface PathsDto { | |
auth: PathsAuthDto; | |
} | |
export const paths: PathsDto = { | |
auth: { | |
current: `${apiEndpoint}/api/auth/current`, | |
login: `${apiEndpoint}/api/auth/login`, | |
signIn: `${apiEndpoint}/api/auth/signIn` | |
} | |
}; | |
// USAGE | |
import { Injectable, Inject } from '@angular/core'; | |
import { HttpClient } from '@angular/common/http'; | |
import { Observable } from 'rxjs'; | |
import { | |
LoginRequestDto, | |
LoginResponseDto, | |
SignInRequestDto, | |
SignInResponseDto | |
} from '../models/auth'; | |
import { paths, PathsAuthDto, PathsDto } from '../config'; | |
@Injectable({ providedIn: 'root' }) | |
export class AuthService { | |
endpoint: PathsAuthDto; | |
constructor(private http: HttpClient, @Inject(paths) paths: PathsDto) { | |
this.endpoint = paths.auth; | |
} | |
login(data: LoginRequestDto): Observable<LoginResponseDto> { | |
return this.http.post<LoginResponseDto>(this.endpoint.login, data); | |
} | |
signIn(data: SignInRequestDto): Observable<SignInResponseDto> { | |
return this.http.post<SignInResponseDto>(this.endpoint.signIn, data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment