I am trying to implement logout functionality in my app. Once I logout, how should refresh all the pages to display content corresponding to the logout state?
Tried running a check method on each page during initialization. The problem is that this happens only once. I want to make the check dynamic.
I do not deal with this at all. Hear me how I organize my login/logout.
Login, Agreement page, EULA, etc..., are usually displayed before the user can perform any actions.
The entry point is the Login page. To be able to do "//LoginPage", you need to define it as separate ShellItem. (Otherwise you get exception, that this type of navigation is not supported)
You then can use EventToCommand behavior to bind your "OnAppearing" event to your LoginViewModel. And make the IsLogged check there, redirecting the user to the HomePage. (Navigation happens with //HomePage, so the user cannot go back there, without Logout button.
Logout button clears the IsLogged status, and navigates you back to //LoginPage. (so you cant go back, without logging in.)
At the same the AccessToken may get invalid at some point. (While you are logged in).
One way to handle this is to catch HttpRequestException. And use ResponseCode to detect Unauthorized(401). At this point you clear IsLogged status, and navigate the user to LoginPage to re-enter credentials.
The display logic I handle in OnAppearing. You can use that too.
If you still want to do it your way, do not try to reconstruct your pages. The time you need to refresh some VisualElements is nothing, compared to calling constructors.