Hi, I use ember-simple-auth-token extension. I can authenticate but when I try get ember data by
this.store.findAll('post')
the request is without Authorization with Bearer + token.
Can someone show me what I do wrong?
My setup:
ember - octane
ember-cli: 3.9.0
node: 10.15.3
"ember-data": "github:emberjs/data#1df833396855d956b817540923dd89338463fec2",
"ember-simple-auth-token": "^4.0.7",
app/adapters/application.js
import DS from 'ember-data';
import TokenAuthorizerMixin from 'ember-simple-auth-token/mixins/token-authorizer';
const { JSONAPIAdapter } = DS;
export default class ApplicationAdapter extends JSONAPIAdapter.extend(TokenAuthorizerMixin) {
host = 'http://api.myproject.local';
namespace = 'v1';
}
app/initializers/application.js
import Inflector from 'ember-inflector';
export function initialize(/* application */) {
// application.inject('route', 'foo', 'service:foo');
const inflector = Inflector.inflector;
inflector.uncountable('post');
}
export default {
initialize
};
app/models/post.js
import DS from 'ember-data';
const { Model, attr } = DS;
export default class PostModel extends Model {
@attr('number') id;
@attr('string') title;
}
app/routes/application.js
import Route from '@ember/routing/route';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
export default class ApplicationRoute extends Route.extend(ApplicationRouteMixin) {
}
app/routes/index.js
import Route from '@ember/routing/route';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
import { inject as service } from '@ember/service';
export default class IndexRoute extends Route.extend(AuthenticatedRouteMixin) {
@service store;
@service session;
model() {
return this.store.findAll('post');
}
}
app/serializers/application.js
import DS from 'ember-data';
export default class ApplicationSerializer extends DS.JSONSerializer {
}
app/session-stores/application.js
import CookieStore from 'ember-simple-auth/session-stores/cookie';
export default CookieStore.extend();
app/routes.js
import EmberRouter from "@ember/routing/router";
import config from "./config/environment";
const Router = EmberRouter.extend({
location: config.locationType,
rootURL: config.rootURL
});
Router.map(function() {
this.route('login');
});
export default Router;
app/config/environment.js
ENV['ember-simple-auth'] = {
authorizer: 'authorizer:token'
};
ENV['ember-simple-auth-token'] = {
refreshAccessTokens: true,
refreshLeeway: 300, // refresh 5 minutes (300 seconds) before expiration
serverTokenEndpoint: 'http://api.myproject.local/v1/user/login', // Server endpoint to send authenticate request
tokenPropertyName: 'token', // Key in server response that contains the access token
// headers: {} // Headers to add to the
};
Thanks for help.