Trying to understand the inconsistency in the response between using my api vs ember-cli-mirage.
I have a handler making a POST request to authenticate a user. The expected parameters for the handler are response
, status
and xhr
. Using my API I receive what I'd expect- response is the data, status is the statusText and xhr is the xhr object. However using ember-cli-mirage everything comes under response (kind of), and status and xhr are both undefined.
Snippets of my code are below:
mirage/config.js
this.post(URI.AUTH_SIGN_IN, function(db, request) {
const responseHeaders = {
'access-token': 'abcxyz123',
'client': 'foobarbaz',
'token-type': 'Bearer',
'expiry': '1497364419',
'uid': 'user@example.com'
};
const user = {
data: { id: 1, type: 'user', attributes: { uid: 'user@example.com', email: 'user@example.com', name: 'John Doe', provider: 'email' } }
};
return new Mirage.Response( 200, responseHeaders, user );
});
authenticators/devise.js
authenticate(identification, password) {
...
this.makeRequest( credentials ).then(function(response, status, xhr) {
// persists the five headers needed to send to devise-token-auth
// with mirage; response = Response {type: "default", status: 200, ok: true, statusText: "OK", headers: Headers…}, status = undefined, xhr = undefined
// with actual api; response = Object {data: Object}, status = "success", xhr = Object {readyState: 4, getResponseHeader: function, getAllResponseHeaders: function…}
});
}
I believe I'm doing it all correctly, but I've been known to be wrong :). Any help is much appreciated.
Aucun commentaire:
Enregistrer un commentaire