I am using ngrx/data and in order to set the store, i use resolver.
user.resolver.ts
@Injectable()
export class UserResolver implements Resolve<any> {
loading = false;
constructor(private userEntityService: UserEntityService) {}
resolve(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<any> {
return this.userEntityService.loaded$.pipe(
tap(loaded => {
if (!loaded) {
this.userEntityService.getAll();
}
}),
filter(loaded => !!loaded),
first()
);
}
}
user.routing.ts
path: '',
component: UsersComponent,
resolve: {
user: UserResolver
},
The problem is when I use resolver, my Auth interceptor doesn't attach token to headers. When i comment the "resolve" out, everything works fine. All the requests are authorized.
auth.interceptor.ts
const userProfileStr = localStorage.getItem('userProfile');
if (userProfileStr) {
const userProfile: User = JSON.parse(userProfileStr);
const jwtToken = userProfile.jwtToken;
const csrf = userProfile.csrf;
let headers = new HttpHeaders();
headers = req.headers
.set('Authorization', jwtToken)
.set('x-csrf-token', csrf)
.set('Content-Type', 'application/json');
const cloneReq = req.clone({ headers });
return next.handle(cloneReq);
} else {
return next.handle(req);
}
What can be the reason?