diff options
Diffstat (limited to 'ufund-ui/src/app/services/users.service.ts')
-rw-r--r-- | ufund-ui/src/app/services/users.service.ts | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts index 28cc266..c570ccf 100644 --- a/ufund-ui/src/app/services/users.service.ts +++ b/ufund-ui/src/app/services/users.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import {HttpClient, HttpHeaders} from '@angular/common/http'; -import {firstValueFrom, Observable, of, Subject} from 'rxjs'; +import {BehaviorSubject, firstValueFrom, Observable} from 'rxjs'; import {User} from '../models/User'; @Injectable({ @@ -8,7 +8,7 @@ import {User} from '../models/User'; }) export class UsersService { - private currentUser : Subject<User> = new Subject(); + private currentUser : BehaviorSubject<User | null> = new BehaviorSubject<User | null>(null); private apiKey: string = ""; private url = "http://localhost:8080/users" @@ -32,8 +32,8 @@ export class UsersService { private http: HttpClient ) {} - createUser(data: User): Observable<User> { - return this.http.post<User>(this.url, data, this.httpOptions) + async createUser(username:string, password:string) { + await firstValueFrom(this.http.post<User>(this.url, {username: username, password: password}, this.httpOptions)) } getUser(id: string): Observable<User> { @@ -48,10 +48,14 @@ export class UsersService { return this.http.delete<boolean>(`${this.url}/${id}`, this.httpOptions) } - getCurrentUser() { + getCurrentUserSubject() { return this.currentUser; } + getCurrentUser() { + return this.currentUser.getValue() + } + async login(username: string, password: string) { let res = this.http.post<string>(this.authUrl, {username: username, password: password}, this.httpOptions2); this.apiKey = await firstValueFrom(res); |