diff --git a/src/Inc.TeamAssistant.Gateway/Bff/AccountsController.cs b/src/Inc.TeamAssistant.Gateway/Bff/AccountsController.cs index 8a5f8d65..6d8356b5 100644 --- a/src/Inc.TeamAssistant.Gateway/Bff/AccountsController.cs +++ b/src/Inc.TeamAssistant.Gateway/Bff/AccountsController.cs @@ -67,11 +67,15 @@ public async Task LoginAsSuperUser(string? returnUrl) } [HttpGet("logout")] - public async Task Logout(string? returnUrl) + public async Task Logout(string? languageCode) { await HttpContext.SignOutAsync(ApplicationContext.AuthenticationScheme); - return Redirect(DetectTargetUrl(returnUrl)); + var path = string.IsNullOrWhiteSpace(languageCode) + ? "/" + : $"/{languageCode}/"; + + return Redirect(path); } private string DetectTargetUrl(string? returnUrl) diff --git a/src/Inc.TeamAssistant.WebUI/Features/Layouts/MainNavbar.razor b/src/Inc.TeamAssistant.WebUI/Features/Layouts/MainNavbar.razor index 9927f489..b866579e 100644 --- a/src/Inc.TeamAssistant.WebUI/Features/Layouts/MainNavbar.razor +++ b/src/Inc.TeamAssistant.WebUI/Features/Layouts/MainNavbar.razor @@ -18,7 +18,7 @@
@person.Username - + @Resources[Messages.Navigation_Logout] @@ -43,11 +43,16 @@ private IDisposable? _routerScope; private string MainUrl => NavRouter.CreateRoute(null); - private string LogoutUrl => $"accounts/logout?returnUrl={NavRouter.CurrentUrl}"; + private string _logoutUrl = string.Empty; protected override void OnInitialized() { + var languageId = NavRouter.GetCurrentLanguage(); + _routerScope = NavRouter.OnRouteChanged(StateHasChanged); + _logoutUrl = languageId is null + ? "accounts/logout" + : $"accounts/logout?languageCode={languageId.Value}"; } public void Dispose() => _routerScope?.Dispose(); diff --git a/src/Inc.TeamAssistant.WebUI/Routing/NavRouter.cs b/src/Inc.TeamAssistant.WebUI/Routing/NavRouter.cs index abdf6fcb..17ef5277 100644 --- a/src/Inc.TeamAssistant.WebUI/Routing/NavRouter.cs +++ b/src/Inc.TeamAssistant.WebUI/Routing/NavRouter.cs @@ -1,7 +1,6 @@ using Inc.TeamAssistant.Primitives.Languages; using Inc.TeamAssistant.WebUI.Contracts; using Inc.TeamAssistant.WebUI.Extensions; -using Inc.TeamAssistant.WebUI.Services.ClientCore; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Routing; using Microsoft.JSInterop; @@ -39,13 +38,20 @@ public string GetRouteSegment() return routeWithoutLanguage; } + public LanguageId? GetCurrentLanguage() + { + var languageContext = _renderContext.GetLanguageContext(); + + return languageContext.Selected + ? languageContext.CurrentLanguage + : null; + } + public NavRoute CreateRoute(string? routeSegment) { var link = string.IsNullOrWhiteSpace(routeSegment) ? "/" : routeSegment; - var languageContext = _renderContext.GetLanguageContext(); - var selectedLanguage = languageContext.Selected ? languageContext.CurrentLanguage : null; - return new NavRoute(selectedLanguage, link); + return new NavRoute(GetCurrentLanguage(), link); } public IDisposable OnRouteChanged(Action onRouteChanged)