Skip to content

Instantly share code, notes, and snippets.

@whisher
Created November 18, 2021 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whisher/79ced5a625899f9d8375509e18b5439c to your computer and use it in GitHub Desktop.
Save whisher/79ced5a625899f9d8375509e18b5439c to your computer and use it in GitHub Desktop.
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