Handling logout or user switching
So your Flex app loads a bunch of data into models, configures sections of the application based on user permissions, all kinds of user-specific setup. What’s the best way to handle resetting the views and models when the current user switches or logs out?
In a current project I had the idea of redirecting to an HTML page that handles the login process, this way the SWF is unloaded, and on successful login reloaded(hopefully from cache). Well, if the login screen is embedded in the Flex app your life can be made even easier by redirecting the user to the same page your app was loaded from. Part of our deploy process renames the html-template for our application to index.html, so the process looks something like this:
private function logout():void
{
var appURL:String = Application.application.url;
navigateToURL(new URLRequest
(appURL.substring(0,appURL.lastIndexOf("/"))),'_self');
}
Since the application SWF is hopefully cached, this has the effect of just looking like you took the user back to the normal login screen, except the application has been completely reloaded and as a programmer you can be lazy and get back to writing that sweet 3D Rotating List and not have to worry about things like resetting data models, etc.