Files
lmnp-organizer/frontend/src/app/services/session.service.ts
T
nessar e02ad54bcb feat: add unit and integration tests for rental management domain
- Introduced RentPaymentCorrectionTest and RentPaymentTest to validate payment and refund logic.
- Added PhoneNumberTest to ensure proper normalization of phone numbers.
- Created TenantTest to verify attachment management and tenant referencing.
- Implemented ReplacementRentalApiJourneyIT for end-to-end testing of rental and payment workflows.
- Documented architectural decisions in ADR-0014, emphasizing strict DDD boundaries and transaction management.
2026-08-17 14:18:15 +02:00

50 lines
1.5 KiB
TypeScript

import { HttpClient } from '@angular/common/http';
import { computed, Injectable, inject, signal } from '@angular/core';
interface UserResponse {
authenticated: boolean;
username?: string;
email?: string;
}
export type SessionStatus = 'checking' | 'authenticated' | 'anonymous' | 'signing-out' | 'error';
@Injectable({ providedIn: 'root' })
export class SessionService {
private readonly http = inject(HttpClient);
readonly status = signal<SessionStatus>('checking');
readonly isLoggedIn = computed(() => this.status() === 'authenticated');
readonly username = signal('');
readonly email = signal('');
refresh(): void {
this.status.set('checking');
this.http.get<UserResponse>('/api/user').subscribe({
next: (user) => {
this.status.set(user.authenticated ? 'authenticated' : 'anonymous');
this.username.set(user.authenticated ? user.username || 'User' : '');
this.email.set(user.authenticated ? user.email || '' : '');
},
error: () => {
this.status.set('error');
this.username.set('');
this.email.set('');
},
});
}
logout(): void {
if (this.status() === 'signing-out') return;
this.status.set('signing-out');
this.http.post('/logout', null, { responseType: 'text' }).subscribe({
next: () => {
window.location.href = '/';
},
error: () => {
this.status.set('authenticated');
window.alert('Impossible de vous déconnecter. Réessayez.');
},
});
}
}