Another store.ts file code that you need to reproduce the issue in Nativescript + Angular project.
Just install ‘js-data’ and ‘js-data-http’ dependencies in package.json to reproduce the issue:
/// store.ts
import {
DataStore,
Mapper,
Record,
Schema,
utils
} from 'js-data’
import {HttpAdapter} from ‘js-data-http’
export const adapter = new HttpAdapter({
// http: HttpClient,
basePath: ‘http://localhost:8080/api’,
beforeHTTP: function (config, opts) {
config.headers || (config.headers = {});
config.headers.authorization = Bearer ${localStorage.getItem('token')}
;
// Now do the default behavior
return HttpAdapter.prototype.beforeHTTP.call(this, config, opts);
}
})
export const store = new DataStore({})
store.registerAdapter(‘http’, adapter, { default: true })