mercredi 1 juillet 2020

Ember-Data "Error: Assertion Failed: You made a 'findRecord' request for a 'user' with id 'current', but the adapter's response did not have any data"

I'm using Ember 3.17 and trying to set up Ember Data to make a server call using the JSONAPIAdapter, however I keep getting this error:

Error: Assertion Failed: You made a 'findRecord' request for a 'user' with id 'current', but the adapter's response did not have any data

Am I doing something wrong with my adapter?

Below find my adapter, route and the expected data for this call (I have a model set up, with one attribute). The only thing that's a little weird is my endpoint is /users/current but current does not match the ID on the object. (However when I do match the ID, which is a valid endpoint, I get the same error)

adapters/application.js

import JSONAPIAdapter from '@ember-data/adapter/json-api';
import ENV from 'rendia-tv-web/config/environment';

export default class ApplicationAdapter extends JSONAPIAdapter {
  host = ENV.APP.API_HOST;
  namespace = 'tv/v1';

  headers = {
    'Authorization': <authHeader>,
  };

  ajax = function(url, method, hash) {
    hash.crossDomain = true;
    hash.xhrFields = {withCredentials: true};
    return this._super(url, method, hash);
  }
  
}

routes/application.js

import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default class ApplicationRoute extends Route {

  @service store;

  async model() {
    return this.store.findRecord('user', 'current');
  }

}

expected data

{
    "data": {
        "id": "12345",
        "type": "users",
        "attributes": {
            "username": "email@email.com",
            "name": "User 1"
        },
        "relationships": {
            "practice": {
                "data": {
                    "type": "practice",
                    "id": "55555"
                }
            }
        }
    },
    "included": [
        {
            "type": "practice",
            "id": "55555",
            "attributes": {
                "date_created": "2016-09-23T04:21:38-04:00",
                "name": "Practice Name",
                "expiration_date": "2024-10-23T23:59:59-04:00"
            }
        }
    ]
}

Any help is appreciated, thanks!




Aucun commentaire:

Enregistrer un commentaire