Skip to content

Commit da7b135

Browse files
fix: changes interceptors and display error messages
1 parent ef8dafa commit da7b135

File tree

6 files changed

+36
-4
lines changed

6 files changed

+36
-4
lines changed

apps/bytebank/src/interceptors/http.interceptos.ts

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import { AuthFacade } from '@fiap-tech-challenge/shared-data-access';
77
export function loggingInterceptor(req: HttpRequest<unknown>, next: HttpHandlerFn): Observable<HttpEvent<unknown>> {
88
const baseUrl = environment.apiUrl;
99
const authToken = inject(AuthFacade).token$();
10+
11+
if (req.url.includes('/graphql')) return next(req);
12+
1013
const newReq = req.clone({
1114
url: `${baseUrl}${req.url}`,
1215
headers: req.headers.append('Authorization', `Bearer ${authToken}`),

libs/institutional/feature-auth/src/lib/dialogs/login/auth-login.component.html

+7
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,12 @@ <h2 class="text-xl font-semibold text-center">Login</h2>
2929
<button type="submit" class="w-full bg-green-600 text-white p-2 rounded-lg mt-4">
3030
Acessar
3131
</button>
32+
33+
@if (error()) {
34+
<div class="text-red-500 text-sm mt-4">
35+
{{ error() }}
36+
</div>
37+
}
38+
3239
</form>
3340
</div>

libs/institutional/feature-auth/src/lib/dialogs/login/auth-login.component.ts

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class AuthLoginComponent {
1919
#facade = inject(AuthFacade);
2020

2121
isLogged = this.#facade.isLogged$;
22+
error = this.#facade.error$;
2223

2324
form = new AuthenticationForm();
2425

libs/institutional/feature-auth/src/lib/dialogs/register/register.component.html

+6
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,11 @@ <h2 class="text-xl font-semibold text-center mt-4">
4040
<button type="submit" class="w-full bg-orange-500 text-white p-2 rounded-lg mt-4 cursor-pointer">
4141
Criar conta
4242
</button>
43+
44+
@if (error()) {
45+
<div class="text-red-500 text-sm mt-4">
46+
{{ error() }}
47+
</div>
48+
}
4349
</form>
4450
</div>

libs/institutional/feature-auth/src/lib/dialogs/register/register.component.ts

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export class AuthRegisterComponent {
1616
#dialogRef = inject(DialogRef<AuthRegisterComponent>);
1717
#facade = inject(AuthFacade);
1818

19+
error = this.#facade.error$;
20+
1921
form = new RegistrationForm();
2022

2123
close(): void {

libs/shared/data-access/src/lib/application/auth.facade.ts

+17-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export class AuthFacade {
1717
#userName = signal<string>('')
1818
userName$ = this.#userName.asReadonly()
1919

20+
#error = signal<string | null>(null)
21+
error$ = this.#error.asReadonly()
22+
2023
storeToken(token: string) {
2124
localStorage.setItem('token', token)
2225
}
@@ -34,24 +37,34 @@ export class AuthFacade {
3437
}
3538

3639
login(credentials: AuthUser) {
40+
this.#error.set(null)
3741
return this.#repository.login(credentials).pipe(takeUntilDestroyed(this.#destroyRef)).subscribe({
3842
next: ({ data, errors }) => {
3943
if (data && !errors) {
4044
this.#token.set(data.login.accessToken)
4145
this.storeToken(data.login.accessToken)
4246
this.#isLogged.set(true);
4347
}
44-
if (!data && errors) this.#isLogged.set(false)
45-
}
48+
if (!data && errors) {
49+
this.#isLogged.set(false);
50+
this.#error.set(errors[0].message)
51+
}
52+
},
53+
error: () => this.#error.set('Erro ao realizar login')
4654
})
4755
}
4856

4957
register(credentials: RegisterUser) {
58+
this.#error.set(null)
5059
return this.#repository.register(credentials).pipe(takeUntilDestroyed(this.#destroyRef)).subscribe({
5160
next: ({ data, errors }) => {
5261
if (data && !errors) this.#isLogged.set(true)
53-
if (!data && errors) this.#isLogged.set(false)
54-
}
62+
if (!data && errors) {
63+
this.#isLogged.set(false);
64+
this.#error.set('Erro ao criar o cadastro')
65+
}
66+
},
67+
error: () => this.#error.set('Erro ao criar o cadastro')
5568
})
5669
}
5770

0 commit comments

Comments
 (0)