Hello, I’m working on an Ember-based site, and I’ve just been trying to fix a bug in which a newly logged in user can see the last logged in user’s data. The problem was that I wasn’t clearing the previous user’s data on logout. My research and exploration seem to indicate that Ember provides only one way to do this: Application.reset(); and that it is intended by the Ember developers that I use that method in this case, though reset() may actually be primarily designed for use in automated testing or some such. Is all that correct?
I’ve gone ahead and tried to use Application.reset() to clear user data. It didn’t work well.
(Actually, before trying that, I tried simply clearing the Ember Data store via a small hack; I think my hack did correctly clear the store, but then I still had problems, because some controllers or views or who knows what were still holding onto some computed properties’ values that included the logged out user’s data. So Application.reset() seemed the only way to go.)
The problem was that I actually need some things to be remembered across the cache-clearing operation. For instance, if my site’s server logs the user out for some reason but the browser doesn’t know it yet, then when the user tries to hit a login-protected page, they’ll be redirected to the login page and shown a message to the effect of “You’ve been logged out [for reason X]; please log in again.” On logout, I want to clear all private data, yes–but I want to remember (in the LoginController) that the special message is to be shown.
These are small problems, and there are probably a number of simple, decent ways to solve them that work with Application.reset(). For instance, maybe I could pass parameters across login/logout via sessionStorage, cookies, or URL parameters. But I tentatively claim that I shouldn’t have to rewrite my previously working features just because I didn’t know from the start that you’re supposed to be ready to forget EVERYTHING as soon as a user (explicitly or implicitly) logs out. My problem would be much easier to solve if I could simply tell Ember to clear “everything except what’s in controllers X, Y, and Z” or some such. Is there a fundamental reason why Ember shouldn’t include a feature that’d make something like that easy? Is it just something that the developers haven’t gotten around to implementing? Or… is there something like that already that I just haven’t found?
I learn from https://github.com/emberjs/data/issues/235 that, as of most of a year ago, you just weren’t supposed to be able to pass things around among controllers across logout events, if you wanted to clear your data on logout. Assuming I’m interpreting things correctly. And I don’t seem to be finding any update to that conversation.
(As a side issue–although I did work around the problems I was having with the loss of the parameters I was passing, I still ultimately couldn’t use Application.reset(), because no matter where I tried calling it, it seemed to break things and cause arcane exceptions. If use of this method on logout is intended, then more documentation on that usage would be helpful. As it is, I’ve resorted to simply refreshing the page, which is much much easier.)