Answer the question
In order to leave comments, you need to log in
How to properly add headers to ember.js adapter?
Good day.
Trying to make authorization on a bunch of ember - django.
Wrote a controller with a form and action - login, django. issues a token, but this token needs to be added to the request headers, and this is where the problem arises.
controler/login.js
actions: {
login: function() {
var obj = this;
Ember.$.ajax({
// настройка запроса
success: function(data) {
return function(data, self){
// варианты найденные в интернетах
// DS.RESTAdapter.reopen({
// headers: {
// 'Authorization': "Token "+data.token
// }
// });
// еще один вариант
Ember.$.ajaxSetup({
headers: {
'Authorization': "Token "+data.token
}
});
self.transitionToRoute(self.returnTo);
}(data, obj)
}
});
}
}
adapters/test_model.js
export default ApplicationAdapter.extend({
pathForType: function(type) {
// переопределение адреса РЕСТ для конкретной модели
return "name_models/";
}
});
Answer the question
In order to leave comments, you need to log in
Hello.
I advise you not to waste time on your authorizations, but to use ember-simple-auth and its module for authorization in django, for example ember-cli-django-rest-auth .
In addition, in any case, in addition to the token, you will need a session with an authorized user and store all this somewhere and forward it to different places in the application, ember-simple-auth does all this.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question