Skip to content

Commit

Permalink
Clean JWT interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelim01 committed Oct 17, 2024
1 parent 383be75 commit f096a0e
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions frontend/src/_interceptors/jwt.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ import { User } from '../_models/user.model';

@Injectable()
export class JwtInterceptor implements HttpInterceptor {
private currentUser: User | null | undefined;
constructor(private authenticationService: AuthenticationService) {
this.authenticationService.user$.subscribe(user => {
this.currentUser = user;
});
}
private currentUser?: User;
constructor(private authenticationService: AuthenticationService) {}

intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
// add auth header with jwt if user is logged in and request is to the api url
const isLoggedIn = this.currentUser?.accessToken;
const isLoggedIn = this.authenticationService.userValue?.accessToken;
const isApiUrl = request.url.startsWith(environment.UserServiceApiUrl);
if (isLoggedIn && isApiUrl) {
request = request.clone({
Expand Down

0 comments on commit f096a0e

Please sign in to comment.