Minha alteração
This commit is contained in:
parent
8729ffddbb
commit
70fc642286
|
|
@ -3,6 +3,7 @@ import { inject, PLATFORM_ID } from '@angular/core';
|
|||
import { isPlatformBrowser } from '@angular/common';
|
||||
import { catchError, throwError } from 'rxjs';
|
||||
import { SessionNoticeService } from '../services/session-notice.service';
|
||||
import { AuthService } from '../services/auth.service';
|
||||
|
||||
export const sessionInterceptor: HttpInterceptorFn = (req, next) => {
|
||||
const platformId = inject(PLATFORM_ID);
|
||||
|
|
@ -11,11 +12,18 @@ export const sessionInterceptor: HttpInterceptorFn = (req, next) => {
|
|||
}
|
||||
|
||||
const sessionNotice = inject(SessionNoticeService);
|
||||
const authService = inject(AuthService);
|
||||
|
||||
const url = (req.url || '').toLowerCase();
|
||||
const isAuthRequest = url.includes('/auth/login') || url.includes('/auth/register');
|
||||
|
||||
return next(req).pipe(
|
||||
catchError((err: HttpErrorResponse) => {
|
||||
if (err?.status === 401) {
|
||||
sessionNotice.handleUnauthorized();
|
||||
// 401 durante /auth/login = credenciais inválidas, não "sessão expirada".
|
||||
if (!isAuthRequest && !!authService.token) {
|
||||
sessionNotice.handleUnauthorized();
|
||||
}
|
||||
} else if (err?.status === 403) {
|
||||
sessionNotice.handleForbidden();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue