begin auth cookie
This commit is contained in:
@@ -36,7 +36,7 @@ export class ScreenLogin {
|
||||
|
||||
this.api.login(this.loginForm.value.username, this.loginForm.value.password).subscribe({
|
||||
next: () => {
|
||||
//this.router.navigate(['']);
|
||||
this.router.navigate(['']);
|
||||
},
|
||||
error: (err) => {
|
||||
this.error = err.error?.message || 'Login failed. Please try again.';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { BehaviorSubject, catchError, map, Observable, of, tap } from 'rxjs';
|
||||
import Transaction from '@model/transaction'
|
||||
|
||||
@Injectable({
|
||||
@@ -8,6 +8,8 @@ import Transaction from '@model/transaction'
|
||||
})
|
||||
export class APIService {
|
||||
private apiUrl = 'http://localhost:3000/api'
|
||||
private isAuthenticatedSubject = new BehaviorSubject<boolean>(false);
|
||||
isAuthenticated$ = this.isAuthenticatedSubject.asObservable();
|
||||
|
||||
constructor(private http: HttpClient){}
|
||||
|
||||
@@ -20,4 +22,14 @@ export class APIService {
|
||||
logout(): Observable<any>{
|
||||
return this.http.post(this.apiUrl + '/auth/logout', {});
|
||||
}
|
||||
checkAuthStatus(): Observable<boolean> {
|
||||
return this.http.get(`${this.apiUrl}/auth/status`, { withCredentials: true }).pipe(
|
||||
map(() => true),
|
||||
catchError(() => of(false)),
|
||||
tap({
|
||||
next: () => this.isAuthenticatedSubject.next(true),
|
||||
error: () => this.isAuthenticatedSubject.next(false),
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user