Skip to content

Commit dfc3dfb

Browse files
committed
Fix token interception
1 parent 989afea commit dfc3dfb

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/app/core/auth/auth.interceptor.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ export const authInterceptor = (req: HttpRequest<unknown>, next: HttpHandlerFn):
1717
const authService = inject(AuthService)
1818
const router = inject(Router)
1919

20-
// Clone the request object
21-
const newReq = req.clone()
20+
let newReq: HttpRequest<unknown>
2221

2322
// If the access token didn't expire, add the Authorization header to api requests.
2423
// We won't add the Authorization header if the access token expired, which forces a 401 response from Django.
2524
// The response interceptor will catch and delete the access token from local storage while signing out the user.
2625
if (/^\/?api\//.test(req.url) && authService.accessToken && !AuthUtils.isTokenExpired(authService.accessToken)) {
27-
newReq.headers.set('Authorization', `Bearer ${authService.accessToken}`)
26+
newReq = req.clone({
27+
headers: req.headers.set('Authorization', `Bearer ${authService.accessToken}`),
28+
})
29+
} else {
30+
newReq = req.clone()
2831
}
2932

3033
// Response

0 commit comments

Comments
 (0)