Home > Back-end >  Logging out from tab, not working for all other tabs
Logging out from tab, not working for all other tabs

Time:12-19

I've implemented login functionality using custom cookie authentication and its working well.

When I am logging out from one tab it is working find, once use do log out user will redirect to logout screen. but when I have opened more than one tab, user can still access the pages in other tab.

If I do refresh the page in other tab, user is logging out.

It is working only if I manually refresh the page, how can I logout user without refresh the page.

How can I refresh application state.

CodePudding user response:

you have to continously make a ajax call to server or refresh the page through meta tag in a fix interval of time. But it's not good idea as design,or if you use custome cookie follow it [1]: https://github.com/aspnet/AspNetCore/issues/14996

CodePudding user response:

In Blazor, every tab runs on a different blazor session Id. Therefore, even when you log out, it will not automatically log you out from the rest of the opened tab. It is the expected behavior. They all are using the same object but with different session ids. Therefore, whatever changes happen in one of the tabs will not reflect in the others. One way to communicate between multiple tabs is to use local storage. It is the place that all browser tabs share commonly.

In my current Blazor application, I have done something similar. After login, I have added a key-value pair (e.g., date timestamp) into the browser's local storage. Additionally, a setInterval() is registered, which tracks the user's activity. It also checks for the key added at the time of login. Log out from any of the tabs remove the key. When other browser tabs do not find that key, they redirect to the login page.

  • Related