basic login/logout

This commit is contained in:
eneller
2026-03-07 14:48:19 +01:00
parent 111d1a7b48
commit f5ae9ac9e6
7 changed files with 49 additions and 16 deletions

View File

@@ -11,6 +11,7 @@
<i class="bi bi-wallet2 fs-4"></i>
<h3 class="mb-0">{{ balance | currency}}</h3>
</div>
<button type="button" (click)="logOut()" class="btn btn-outline-secondary">Log out</button>
</div>
</div>

View File

@@ -2,6 +2,7 @@ import { CommonModule, CurrencyPipe, DatePipe } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { APIService } from '../../services/api';
import Transaction from '@model/transaction';
import { Router } from '@angular/router';
@Component({
selector: 'app-screen-profile',
@@ -15,7 +16,10 @@ export class ScreenProfile implements OnInit{
balance = 200;
transactions!: Transaction[];
constructor(private api: APIService){}
constructor(
private api: APIService,
private router: Router,
){}
ngOnInit(): void {
// FIXME transactions displaying delayed (only on second nav click)
@@ -28,5 +32,15 @@ export class ScreenProfile implements OnInit{
},
})
}
logOut(){
this.api.logout().subscribe({
next: () => {
this.router.navigate(['login'])
},
error: (err) => {
console.error('Error logging out:', err)
}
})
}
}

View File

@@ -17,4 +17,7 @@ export class APIService {
login(username: string, password: string): Observable<any>{
return this.http.post(this.apiUrl + '/auth/login',{ 'username': username, 'password': password});
}
logout(): Observable<any>{
return this.http.post(this.apiUrl + '/auth/logout', {});
}
}