File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
src/context/auth/application/facades Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ import { Injectable } from '@angular/core' ;
2+ import { LoginUseCase } from '../login.use-case' ;
3+ import { AuthUser } from '../../domain/user/user.entity' ;
4+ import { AuthStatePort } from '../../domain/port/auth-state.port' ;
5+
6+ @Injectable ( )
7+ export class AuthFacade {
8+ readonly user$ = this . authStatePort . user$ ;
9+ readonly isAuthenticated$ = this . authStatePort . isAuthenticated$ ;
10+ readonly isLoading$ = this . authStatePort . isLoading$ ;
11+
12+ constructor (
13+ private readonly loginUseCase : LoginUseCase ,
14+ private readonly authStatePort : AuthStatePort ,
15+ ) { }
16+
17+ async login ( email : string , password : string ) : Promise < AuthUser > {
18+ const result = await this . loginUseCase . execute ( email , password ) ;
19+
20+ if ( result ) {
21+ const user = result ;
22+ this . authStatePort . setUser ( user ) ;
23+ }
24+
25+ return result ;
26+ }
27+
28+ async logout ( ) : Promise < void > {
29+ // Llamar al caso de uso de logout si existe
30+
31+ this . authStatePort . clearUser ( ) ; // Eliminar usuario del estado
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments