I'm building an twitter like app. So user can access page, then sign up an account, send a twitts.
In this app, I have 1 layout and 3 views which have 3 template with 3 controller. All of them render base on hash url. They are:
- #/home -- home.html, HomeCtrl ---- A public page, so Server side will send the stream line, if user logged in, then show the info they followed, if not, then show the newest messages
- #/my -- my.html, MyCtrl --- A private page, Server side will send the messages which create by current logged in user
- #/account - account.html, AccountCtrl --- A private page, Server side will send the account info(email, name etc....) base on current logged in user.
and in layout, I have a topbar which have 3 links for 3 views, and 3 buttons say login, logout and signup.
When user click login button, I show a popup form, user enter email password, then the data will send back to server and server will put account info into login cookie then when server get request, server will see the request as a logged in request. If the request asking for a private infomation, but not logged in, server will return a 401 error.
In angular, I set an interceptor for httpProvider. So if the ajax request got a 401 error, then I show a login form to ask login.
Everything works fine, so if user access #/home, I show the data, then user access #/my, I show the my messages, if user not logged in, I show a login form. All good.
But, there always a but, when user logged in, then they access #my, then they access #/account, then they click logout button. A logout request send to server and server remove the login cookie. But the thing is user still stay on #/account page, and their account infomation still there which is incorrect.
I know I can set clear the account infomation when they click logout, but which means I need to clear all infomation for all controller and I will have more and more private controller which obviously silly.
So in angular framework, what's the idea for this kind of situation. Please add your thought here. Thanks.