1

"app.get('/api/users', passport.authenticate('jwt', {session: false}), (req, res, next) => {... bla bla bla...}."

getAll() {

const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'Bearer validToke.' 
  });
};

return this.http.get<user[]>(`http://localhost:3000/api/users`, httpOptions);
}

I can authenticate from angular and get the Bearer token, everything works correctly, I can get the list of users if I remove passport.authenticate ('jwt', {session: false})

|

    2

    0

    getAll() {
    
    const httpHeaders = new HttpHeaders ({
         'Content-Type': 'application/json',
         'Authorization': 'Bearer validToke.' 
       });
    
    return this.http.get<user[]>(`http://localhost:3000/api/users`, { headers: httpHeaders });
    }
    

    |
      0

      import { Injectable } from '@angular/core';
          import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http';
          import { Observable } from 'rxjs';
      
          import { AuthenticationService } from '../_services/authentication.service';
      
          @Injectable()
          export class JwtInterceptor implements HttpInterceptor {
            constructor(private authenticationService: AuthenticationService) {}
      
            intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
              // add authorization header with jwt token if available
              let currentUser = this.authenticationService.currentUserValue;
              if (currentUser && currentUser.token) {
                request = request.clone({
                  setHeaders: {
                    Authorization: `${currentUser.token}`
                  }
                });
              }
      
              return next.handle(request);
            }
          }
      

      |