Skip to content

Commit

Permalink
Merge pull request #19569 from abpframework/liangshiwei/authenticatio…
Browse files Browse the repository at this point in the history
…nSessionstateMVC

Add authentication-state-listener js to logout from other tabs for MVC UI
  • Loading branch information
maliming authored Apr 18, 2024
2 parents fa83591 + f9eb84c commit 94f43a0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override void ConfigureServices(ServiceConfigurationContext context)
{
options.FileSets.AddEmbedded<AbpAspNetCoreMvcUiThemeSharedModule>("Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared");
});

Configure<AbpBundlingOptions>(options =>
{
options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public override void ConfigureBundle(BundleConfigurationContext context)
"/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js",
"/libs/abp/aspnetcore-mvc-ui-theme-shared/sweetalert2/abp-sweetalert2.js",
"/libs/abp/aspnetcore-mvc-ui-theme-shared/toastr/abp-toastr.js",
"/libs/abp/aspnetcore-mvc-ui-theme-shared/date-range-picker/date-range-picker-extensions.js"
"/libs/abp/aspnetcore-mvc-ui-theme-shared/date-range-picker/date-range-picker-extensions.js",
"/libs/abp/aspnetcore-mvc-ui-theme-shared/authentication-state/authentication-state-listener.js"
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(function () {

const stateKey = 'authentication-state-id';

window.addEventListener('load', function () {
if (!abp || !abp.currentUser) {
return;
}

if (!abp.currentUser.isAuthenticated) {
localStorage.removeItem(stateKey);
} else {
localStorage.setItem(stateKey, abp.currentUser.id);
}

window.addEventListener('storage', function (event) {

if (event.key !== stateKey || event.oldValue === event.newValue) {
return;
}

if (event.oldValue || !event.newValue) {
window.location.reload();
} else {
location.assign('/')
}
});
});

}());

0 comments on commit 94f43a0

Please sign in to comment.