source: bus-n-go-pavel-216049/bus-n-go-frontend/src/app/services/auth/auth.service.ts

Last change on this file was baf4cc4, checked in by ppaunovski <paunovskipavel@…>, 3 months ago

split group project and individual project into two separate folders

  • Property mode set to 100644
File size: 1.2 KB
Line 
1import { Injectable } from '@angular/core';
2import {Observable, Subject} from "rxjs";
3import {HttpClient, HttpHeaders} from "@angular/common/http";
4import {AuthResponse} from "../../model/responses/AuthResponse";
5import {AuthRequest} from "../../model/requests/AuthRequest";
6import {RegisterRequest} from "../../model/requests/RegisterRequest";
7
8@Injectable({
9 providedIn: 'root'
10})
11export class AuthService {
12 refreshAuth$ = new Subject<boolean>();
13 private url = '/api/auth';
14
15 constructor(private http: HttpClient) { }
16
17 login(authRequest: AuthRequest): Observable<AuthResponse> {
18 return this.http.post<AuthResponse>(
19 `${this.url}`,
20 JSON.stringify(authRequest),
21 {
22 headers: new HttpHeaders({ 'Content-Type': 'application/json' })
23 }
24 )
25 }
26
27 register(registerRequest: RegisterRequest): Observable<AuthResponse> {
28 return this.http.post<AuthResponse>(
29 `${this.url}/register`,
30 JSON.stringify(registerRequest),
31 {
32 headers: new HttpHeaders({ 'Content-Type': 'application/json' })
33 }
34 )
35 }
36
37 isAuthenticated(): Observable<boolean> {
38 return this.http.get<boolean>(`${this.url}`);
39 }
40
41 isDriverFree(): Observable<boolean> {
42 return this.http.get<boolean>(`${this.url}/is-driver-free`);
43 }
44
45}
Note: See TracBrowser for help on using the repository browser.