From cff20aaf9d7600542f1e84ba0b1ef260d08c4db1 Mon Sep 17 00:00:00 2001 From: Albie Date: Sat, 26 Nov 2022 18:34:13 +0000 Subject: [PATCH] fix redirections not taking place --- DragonFruit.Sakura/Administration/AdminLayout.razor | 10 ++++++++-- DragonFruit.Sakura/Administration/Index.razor | 13 ++++++++++--- DragonFruit.Sakura/Administration/Index.razor.cs | 6 ++++++ DragonFruit.Sakura/Program.cs | 1 + 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/DragonFruit.Sakura/Administration/AdminLayout.razor b/DragonFruit.Sakura/Administration/AdminLayout.razor index 031faf1..4e1ed83 100644 --- a/DragonFruit.Sakura/Administration/AdminLayout.razor +++ b/DragonFruit.Sakura/Administration/AdminLayout.razor @@ -1,4 +1,6 @@ -@inherits LayoutComponentBase +@using Microsoft.Extensions.Options +@using Microsoft.AspNetCore.Components.WebAssembly.Authentication +@inherits LayoutComponentBase @layout DefaultLayout @@ -34,9 +36,13 @@ [Inject] private NavigationManager Navigation { get; set; } + [Inject] + private IOptionsSnapshot> OptionsContainer { get; set; } + private void RedirectToLoginPage() { - Navigation.NavigateTo($"/auth/login?returnUrl={Uri.EscapeDataString(Navigation.Uri)}"); + var path = OptionsContainer.Get(Options.DefaultName).AuthenticationPaths.LogInPath; + Navigation.NavigateToLogin(path); } } \ No newline at end of file diff --git a/DragonFruit.Sakura/Administration/Index.razor b/DragonFruit.Sakura/Administration/Index.razor index 48293ff..f190e25 100644 --- a/DragonFruit.Sakura/Administration/Index.razor +++ b/DragonFruit.Sakura/Administration/Index.razor @@ -5,10 +5,17 @@ - - Welcome Back + + @if (string.IsNullOrEmpty(Name)) + { + Welcome Back + } + else + { + Welcome Back, @Name + } - Manage Keychain + Manage Keychain diff --git a/DragonFruit.Sakura/Administration/Index.razor.cs b/DragonFruit.Sakura/Administration/Index.razor.cs index 165db78..ccf137b 100644 --- a/DragonFruit.Sakura/Administration/Index.razor.cs +++ b/DragonFruit.Sakura/Administration/Index.razor.cs @@ -5,6 +5,7 @@ using DragonFruit.Sakura.Network; using DragonFruit.Sakura.Network.Requests; using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Authorization; namespace DragonFruit.Sakura.Administration { @@ -15,6 +16,10 @@ public partial class Index [Inject] private ApiClient Client { get; set; } + [Inject] + private AuthenticationStateProvider AuthenticationStateProvider { get; set; } + + private string Name { get; set; } private IReadOnlyList Apps { get; set; } private AppFeatures SelectedAppFeature @@ -37,6 +42,7 @@ private AppFeatures SelectedAppFeature protected override async Task OnInitializedAsync() { Apps = await Client.PerformAsync>(new AdminApiAppsListingRequest()).ConfigureAwait(false); + Name = await AuthenticationStateProvider.GetAuthenticationStateAsync().ContinueWith(t => t.Result.User.Identity?.Name).ConfigureAwait(false); } } } diff --git a/DragonFruit.Sakura/Program.cs b/DragonFruit.Sakura/Program.cs index 2f5135a..dcf7fc0 100644 --- a/DragonFruit.Sakura/Program.cs +++ b/DragonFruit.Sakura/Program.cs @@ -49,6 +49,7 @@ public static async Task Main(string[] args) o.ProviderOptions.RedirectUri = "https://dragonfruit.network/auth/login-callback"; #endif + o.ProviderOptions.PostLogoutRedirectUri = "/"; o.ProviderOptions.DefaultScopes.Add("delegate"); o.AuthenticationPaths.LogInPath = "/auth/login";