Search code examples
javascriptember.jsember-simple-auth

Ember Simple Auth - How To Update The Stored Token


On each request my application makes, a token is returned inside the response. This is the token that needs to be used for the next request.

This works (partially). When I refresh the App it runs the restore function but uses the wrong token.

    var Parent = this;

    Ember.$(document).ajaxComplete(function(Event, Response) {

        Parent.session.content.Token = Response.responseJSON.Token;

    });

It would seem that the above code updates the token in memory but not in the store which the authenticator uses upon "restoring" the session using the restore function.

How can I update the token in the localStorage to use this token for all requests/re-validations?


Solution

  • You have to use Ember's set method so the session can detect that the Token has changed: session.set('token', Response.responseJSON.Token);.