diff options
author | Gunther6070 <haydenhartman10@yahoo.com> | 2025-03-15 23:19:56 -0400 |
---|---|---|
committer | Gunther6070 <haydenhartman10@yahoo.com> | 2025-03-15 23:19:56 -0400 |
commit | 47501b0d9765e64eba370ba80bbc7b2cd5940170 (patch) | |
tree | abeda89cd86423119d5a895aa4240de83a974da5 /ufund-ui/src/app/services/users.service.ts | |
parent | 28e46060c8bcf7fd2adc19793bd63e27df4e7356 (diff) | |
parent | d97d4d430113088c4f52f53c040d8705c66b410e (diff) | |
download | JellySolutions-47501b0d9765e64eba370ba80bbc7b2cd5940170.tar.gz JellySolutions-47501b0d9765e64eba370ba80bbc7b2cd5940170.tar.bz2 JellySolutions-47501b0d9765e64eba370ba80bbc7b2cd5940170.zip |
Merge branch 'api-auth' of https://github.com/RIT-SWEN-261-02/team-project-2245-swen-261-02-2b into api-auth
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); |