Open DeinChristian opened 3 years ago
Fix or riot!
Same problem, any solution ??
it happens me too
Someone have any solution ??
Found a solution. The problem is that this library use axios http client and HttpInterceptor not work.
I use a Service derived class like this one and it works.
axios-authentication.service.ts
import { Injectable } from '@angular/core';
import { Resource, Service, } from 'ngx-jsonapi';
import axios from 'axios';
@Injectable({
providedIn: 'root'
})
export abstract class AxiosAuthenticatedService<R extends Resource = Resource> extends Service<R> {
constructor() {
super();
axios.interceptors.request.use(
function (request) {
request.headers = {
'Authorization': 'Bearer ' + YOUR TOKEN HERE
};
console.debug('axios interceptor-- ', request);
return request;
}
);
}}
and use this one to your resources services like this:
import { Injectable } from '@angular/core';
import { Service, } from 'ngx-jsonapi';
import { User } from './users.resource';
import { AxiosAuthenticatedService } from '@app/core/services/axios-authentication/axios-authentication.service';
@Injectable({
providedIn: 'root'
})
export class UsersService extends AxiosAuthenticatedService<User> {
public resource = User;
public type = 'users';
public collections_ttl = 1;
}
We can't intercept requests in version 3.0.0-dev anymore (Angular). That works perfectly in 2.2.3.
example interceptor: