|
|
|
@ -4,6 +4,7 @@ import { Injectable } from '@angular/core';
|
|
|
|
|
import { BehaviorSubject, Observable, tap } from 'rxjs';
|
|
|
|
|
|
|
|
|
|
import { environment } from '../../../environments/environment';
|
|
|
|
|
import { AuthenticationApiService } from '../../api/api/authentication.api.service';
|
|
|
|
|
import { LoginCredentials, Tokens } from '../types';
|
|
|
|
|
|
|
|
|
|
import { LocalStorageService } from './local-storage.service';
|
|
|
|
@ -26,28 +27,29 @@ export class AuthService {
|
|
|
|
|
public constructor(
|
|
|
|
|
private readonly httpClient: HttpClient,
|
|
|
|
|
private readonly localStorageService: LocalStorageService,
|
|
|
|
|
private readonly sessionStorageService: SessionStorageService
|
|
|
|
|
private readonly sessionStorageService: SessionStorageService,
|
|
|
|
|
private readonly authenticationApiService: AuthenticationApiService
|
|
|
|
|
) {
|
|
|
|
|
this.autoLogin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public signin(credentials: LoginCredentials): void {
|
|
|
|
|
this.httpClient
|
|
|
|
|
.post<Tokens>(environment.api.base + `${this._path}/signin`, credentials)
|
|
|
|
|
this.authenticationApiService
|
|
|
|
|
.authControllerSignin(credentials)
|
|
|
|
|
.subscribe((response: Tokens) => {
|
|
|
|
|
this.handleSuccess(response);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public signup(credentials: LoginCredentials): void {
|
|
|
|
|
this.httpClient
|
|
|
|
|
.post<Tokens>(environment.api.base + `${this._path}/signup`, credentials)
|
|
|
|
|
this.authenticationApiService
|
|
|
|
|
.authControllerSignup(credentials)
|
|
|
|
|
.subscribe((response: Tokens) => {
|
|
|
|
|
//TODO The checked accept terms should be saved with a timestamp in the db
|
|
|
|
|
this.handleSuccess(response);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO Implement authControllerSignup
|
|
|
|
|
public signout(): void {
|
|
|
|
|
this._access_token = null;
|
|
|
|
|
this._refresh_token = null;
|
|
|
|
|