1

Beginner in NgRx Data

I have implemented NgRx data in one of my Application module. Everything is working fine the only concern is api's that i am using in NgRx data configured module not triggering the HTTP Interceptor where i configured my Auth Token on Application level.

All other modules where NgRx is not configured is calling HTTP Interceptor properly & setting the TOKENS in API'S properly.

Is it Mandate to store token in NgRx Store then only API'S will call HTTP Interceptor?

Just an FYI. I am not using NgRX store for Storing Token as of now i am storing in localstorage.

1 Answers1

0

From your question w/o any code snippet, it is difficult to understand actual problem. If I understood it clearly you want to add token before request goes on wire. In this case you may want to implement HttpInerceptor. Refer below code snippet. You can check more on it from Bezocder This should solve your problem.

intercept(req: HttpRequest<any>, next: HttpHandler) {
    let authReq = req;
    let jwt = sessionStorage.getItem('token');
    if (jwt != null) {
        // for Spring Boot back-end
        authReq = req.clone({ headers: req.headers.set(TOKEN_HEADER_KEY, 'Bearer ' + jwt) });
    }
    return next.handle(authReq);
}
Tyler2P
  • 2,324
  • 26
  • 22
  • 31