ember-fastboot / ember-fastboot/ember-cli-fastboot

Fastboot + RESTAdapter and Error: Ember Data Request 401

Open
#689 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
850
Forks
161
Avg merge
17h 45m
Merged PRs (30d)
19

Description

@kratiahuja @tomdale

Hope you're doing well.

I need you assistance in the below case.

I am using RESTAdapter for APIs. Unfortunately I am facing issue with API call after authentication which need Authorization in header.

###### Error
```
Error: Ember Data Request GET http://embertaskapi.test/api/tasks returned a 401
Payload (application/json)
[object Object]
at ErrorClass.AdapterError (/tmp/broccoli-9122c1h7IjFHtwVu/out-220-broccoli_merge_trees/assets/addon-tree-output/ember-data/-private.js:6175:1)
at new ErrorClass (/tmp/broccoli-9122c1h7IjFHtwVu/out-220-broccoli_merge_trees/assets/addon-tree-output/ember-data/-private.js:6203:1)
at Class.handleResponse (/tmp/broccoli-9122c1h7IjFHtwVu/out-220-broccoli_merge_trees/assets/addon-tree-output/ember-data/adapters/rest.js:801:1)
at ajaxError (/tmp/broccoli-9122c1h7IjFHtwVu/out-220-broccoli_merge_trees/assets/addon-tree-output/ember-data/adapters/rest.js:1093:1)
at ajaxErrorHandler (/tmp/broccoli-9122c1h7IjFHtwVu/out-220-broccoli_merge_trees/assets/addon-tree-output/ember-data/adapters/rest.js:1139:1)
at Object.hash.error (/tmp/broccoli-9122c1h7IjFHtwVu/out-220-broccoli_merge_trees/assets/addon-tree-output/ember-data/adapters/rest.js:884:1)
at fire (/var/www/html/hands-on-ember/node_modules/jquery-deferred/lib/jquery-callbacks.js:78:30)
at Object.fireWith (/var/www/html/hands-on-ember/node_modules/jquery-deferred/lib/jquery-callbacks.js:188:7)
at Object.fire [as reject] (/var/www/html/hands-on-ember/node_modules/jquery-deferred/lib/jquery-callbacks.js:195:10)
at onError (/var/www/html/hands-on-ember/node_modules/najax/lib/najax.js:208:9)
at dataHandler (/var/www/html/hands-on-ember/node_modules/najax/lib/najax.js:173:9)
at IncomingMessage. (/var/www/html/hands-on-ember/node_modules/najax/lib/najax.js:198:9)
at IncomingMessage.emit (events.js:194:15)
at endReadableNT (_stream_readable.js:1125:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
```
It works fine without fastboot.

###### This is my `adapter.js`
```
import config from '../config/environment';
import DS from 'ember-data';
import { computed } from '@ember/object';
import { inject as service } from '@ember/service';
import { storageFor } from 'ember-local-storage';

export default DS.RESTAdapter.extend({
namespace: "api",
host: config.apiURL,
session: service('session'),
stats: storageFor('stats'),
headers: computed('stats.user', function () {
const user = this.get('stats.user');
// console.log('adpter', user);
return {
'Authorization': `Bearer ${user.access_token}`,
'Accept': 'application/json'
}
})
});

```

Your guidance will be highly appreciated and valuable to me.

Thanks,

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.