javascript - Ember JS set request header -


i trying set auth token recieved response after user registration ember data request header.

here application.js code

import ds 'ember-data';  export default ds.restadapter.extend({    namespace: 'merchant',   host: 'http://192.168.1.173:3000',     headers: function() {     return {       "token":localstorage.token,     };    }.property("localstorage.token","token")  }); 

i trying set header after receiving success response register user api call.

var register=this.store.createrecord('registermerchant',data);   register.save().then(function(response){     console.log(response.success);     if(response.get('success')){         self.set('token',response.get('token'));       self.transitiontoroute('merchanthome')      } 

and

  tokenchanged: function() {      localstorage.token=this.get('token');      console.log(localstorage.token);    }.observes('token'), 

i able see updated localstorage.token value value reason not set reqest header token key.

the token not getting updated header , after doing page refresh new updated token being sent server.

any thoughts on doing wrong,any tips appreciated. thanks

localstorage not observable ember object, property("localstorage.token") evaluated once. instead make volatile re-evaluate property every time:

headers: function() {     return {       "token":localstorage.token,     };    }.property().volatile() 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -