Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add authentication-state-listener js to logout from other tabs for MVC UI #19569

Merged
merged 4 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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('/')
}
});
});

}());
Loading