src/app/Services/auth.service.ts
constructor(http: HttpClient)
|
login |
login(email: string, password: string)
|
Function to login user
Parameters :
Returns:
any
Observable |
register |
register(email: string, username: string, password: string)
|
Function to register user
Parameters :
Returns:
any
Observable |
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
const AUTH_API = 'https://gruppe1.testsites.info/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<any> {
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<any> {
return this.http.post(
AUTH_API + '/register',
{
email,
password,
username,
},
httpOptions
);
}
}