Skip to content

Commit

Permalink
Fixed reset language on login redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
dyatlov-a committed Sep 29, 2024
1 parent cb7d170 commit 4413430
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/Inc.TeamAssistant.Gateway/Bff/AccountsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ public async Task<IActionResult> LoginAsSuperUser(string? returnUrl)
}

[HttpGet("logout")]
public async Task<IActionResult> Logout(string? returnUrl)
public async Task<IActionResult> 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)
Expand Down
9 changes: 7 additions & 2 deletions src/Inc.TeamAssistant.WebUI/Features/Layouts/MainNavbar.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<br/>
@person.Username
</span>
<a href="@LogoutUrl" class="link link_light navbar__item">
<a href="@_logoutUrl" class="link link_light navbar__item">
@Resources[Messages.Navigation_Logout]
</a>
</Authorized>
Expand All @@ -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();
Expand Down
14 changes: 10 additions & 4 deletions src/Inc.TeamAssistant.WebUI/Routing/NavRouter.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4413430

Please sign in to comment.