Skip to content

Commit ec5bb54

Browse files
committed
feat(facade): creates the facade for auth
1 parent 366c524 commit ec5bb54

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}

0 commit comments

Comments
 (0)