import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; const AUTH_API = '/api/user'; const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }), }; @Injectable({ providedIn: 'root', }) export class AuthService { constructor(private http: HttpClient) {} /** * Function to login user * @param {string} email * @param {string} password * @returns Observable */ login(email: string, password: string): Observable { return this.http.post(AUTH_API + '/login', { email, password, }); } /** * Function to register user * @param {string} email * @param {string} username * @param {string} password * @returns Observable */ register(email: string, username: string, password: string): Observable { return this.http.post( AUTH_API + '/register', { email, password, username, }, httpOptions ); } }