lundi 8 juin 2015

How to redirect to login page if get the 401 error when I use ember-simple-auth?

"ember-simple-auth": "0.7.3"

My ember.js application model is not use ember data and use Ember.Object to set the ajax api url.

After I login successfuly, I change the token and I will get 401 errors. Like:

GET http://localhost:3000/api/account.json 401 (Unauthorized)

But the page is empty, if I am a user I don't know what is happen? I think if get the 401 error is redirect to login page is will be better.

So I try route error action:

  actions: {
    error: function(error, transition) {

      if (error && error.status === 401) {
        // error substate and parent routes do not handle this error
        return this.transitionTo('login');
      }

      // Return true to bubble this event to any parent route.
      return true;
    }
  }

But it can not redirect to the login page.
Any help please.

Aucun commentaire:

Enregistrer un commentaire