jeudi 19 février 2015

Ember Simple Auth - logging in loads previous session's data

I'm having a problem with Ember Simple Auth where logging out and invalidating a user does not delete the data for the restore function in the custom authenticator. So, when I log in with another user, it restores the old user's session.


In the invalidate method, if I add something like 'window.location.reload(true)', everything works but obviously this is a very hacky way to do it.


Anyone know how to reload the application or remove the restore function's data with Ember Simple Auth? I need a elegant solution!


Here's my custom authenticator:



var CustomAuthenticator = Base.extend({
restore: function(data) {
return new Ember.RSVP.Promise(function (resolve, reject){
if(!Ember.isEmpty(data.token)) {
console.log(data);
resolve(data);
} else {
reject();
}
});
},
authenticate: function(credentials) {
var loginEmail;
if(credentials.identification) {
loginEmail = credentials.identification;
} else if(credentials.email) {
loginEmail = credentials.email;
}

return new Ember.RSVP.Promise(function (resolve, reject){
var loginPromise = Ember.$.post('/login', {'email':loginEmail, 'password':credentials.password} );
loginPromise.then(function (data){
resolve({
token: data.user.api_key,
userData: data.user
});
}, function(error){
reject(error);
});
});
},
invalidate: function(session){
return new Ember.RSVP.Promise(function(resolve, reject){
resolve();
});
}
});


UPDATE 1:


It might not have anything to do with the restore function. It's most likely an application reload issue.


Aucun commentaire:

Enregistrer un commentaire