Reputation: 13
I'm pretty new to Ember.js
and ember-simple-auth
, so I hope you can help me.
I'm using ember-simple-auth
in my application. What I want to do is to invalidate the session when the browser is closed or the user leaves the page. This is only supposed to happen if the user previosly logged in (thats why put it in the authenticate action).
I tried something like this:
actions: {
authenticate: function() {
var _this = this;
this._super().then(null, function(message) {
_this.set('errorMessage', message);
});
$(window).on('beforeunload',function() {
_this.get("session").invalidate();
});
}
}
The problem is that it does not work when closing the browser. Also when I change the URL (to leave the application, for example www.google.com
) it transitions to "/" and does not open the desired URL.
So the question is: How do I invalidate the session when the browser closes (or when the user leaves the application).
Thanks.
Upvotes: 1
Views: 849
Reputation: 4062
I'm not sure how you would handle the case when the user leaves the application (you can probably handle some navigation event and the invalidate the session with this.get("session").invalidate();
). To invalidate the session when the user closes the browser though, the best solution is to use the cookie session store and configure a sessionExpirationTime
of null
so that the cookies are session cookies that get deleted automatically when the browser is closed.
Upvotes: 3