From 46c8f1c3af03845e7af58dd3340f4419a352be81 Mon Sep 17 00:00:00 2001 From: Lucas Morgan Date: Fri, 9 Feb 2024 09:22:20 -0600 Subject: [PATCH] Debugging live-only bug. --- Shogi.Api/Controllers/UserController.cs | 15 --------- Shogi.UI/Pages/Home/Account/AccountManager.cs | 2 -- .../Pages/Home/Api/CookieMessageHandler.cs | 31 ++++++++++++------- Shogi.UI/Pages/Home/Api/ShogiApi.cs | 5 ++- Shogi.UI/Pages/Home/LoginModal.razor | 4 +-- 5 files changed, 23 insertions(+), 34 deletions(-) diff --git a/Shogi.Api/Controllers/UserController.cs b/Shogi.Api/Controllers/UserController.cs index 3b438a4..85973da 100644 --- a/Shogi.Api/Controllers/UserController.cs +++ b/Shogi.Api/Controllers/UserController.cs @@ -91,19 +91,4 @@ public class UserController : ControllerBase await signOutTask; return Ok(); } - - [HttpPut("TestGuestLogout")] - public async Task TestGuestLogout() - { - var signOutTask = HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); - - var userId = User?.GetShogiUserId(); - if (!string.IsNullOrEmpty(userId)) - { - connectionManager.Unsubscribe(userId); - } - - await signOutTask; - return Ok(); - } } diff --git a/Shogi.UI/Pages/Home/Account/AccountManager.cs b/Shogi.UI/Pages/Home/Account/AccountManager.cs index 5865c18..7231234 100644 --- a/Shogi.UI/Pages/Home/Account/AccountManager.cs +++ b/Shogi.UI/Pages/Home/Account/AccountManager.cs @@ -77,7 +77,6 @@ public class AccountManager var platform = await localStorage.GetAccountPlatform(); if (platform == WhichAccountPlatform.Guest) { - Console.WriteLine($"Try Login Silent - {platform}"); var response = await shogiApi.GetToken(WhichAccountPlatform.Guest); if (response != null) { @@ -91,7 +90,6 @@ public class AccountManager } else if (platform == WhichAccountPlatform.Microsoft) { - Console.WriteLine($"Try Login Silent - {platform}"); var state = await authState.GetAuthenticationStateAsync(); if (state.User?.Identity?.Name != null) { diff --git a/Shogi.UI/Pages/Home/Api/CookieMessageHandler.cs b/Shogi.UI/Pages/Home/Api/CookieMessageHandler.cs index cf20575..1a22c29 100644 --- a/Shogi.UI/Pages/Home/Api/CookieMessageHandler.cs +++ b/Shogi.UI/Pages/Home/Api/CookieMessageHandler.cs @@ -2,18 +2,25 @@ namespace Shogi.UI.Pages.Home.Api { - public class CookieCredentialsMessageHandler : DelegatingHandler - { + public class CookieCredentialsMessageHandler : DelegatingHandler + { - public CookieCredentialsMessageHandler() - { - } + public CookieCredentialsMessageHandler() + { + } - protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) - { - request.SetBrowserRequestCredentials(BrowserRequestCredentials.Include); - Console.WriteLine("cookie handler: {0}", request.RequestUri); - return base.SendAsync(request, cancellationToken); - } - } + protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + { + request.SetBrowserRequestCredentials(BrowserRequestCredentials.Include); + try + { + return base.SendAsync(request, cancellationToken); + } + catch + { + Console.WriteLine("Catch!"); + return base.SendAsync(request, cancellationToken); + } + } + } } diff --git a/Shogi.UI/Pages/Home/Api/ShogiApi.cs b/Shogi.UI/Pages/Home/Api/ShogiApi.cs index e17f72a..a1a39e7 100644 --- a/Shogi.UI/Pages/Home/Api/ShogiApi.cs +++ b/Shogi.UI/Pages/Home/Api/ShogiApi.cs @@ -19,7 +19,6 @@ namespace Shogi.UI.Pages.Home.Api public ShogiApi(IHttpClientFactory clientFactory, AccountState accountState) { - Console.WriteLine("ShogiApi constructor"); this.serializerOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web); this.accountState = accountState; this.guestHttpClient = clientFactory.CreateClient(GuestClientName); @@ -35,7 +34,7 @@ namespace Shogi.UI.Pages.Home.Api public async Task GuestLogout() { - var response = await this.guestHttpClient.PutAsync(RelativeUri("User/TestGuestLogout"), null); + var response = await this.guestHttpClient.PutAsync(RelativeUri("User/GuestLogout"), null); response.EnsureSuccessStatusCode(); } @@ -99,6 +98,6 @@ namespace Shogi.UI.Pages.Home.Api return HttpClient.PatchAsync(RelativeUri($"Sessions/{name}/Join"), null); } - private static Uri RelativeUri(string path) => new Uri(path, UriKind.Relative); + private static Uri RelativeUri(string path) => new(path, UriKind.Relative); } } diff --git a/Shogi.UI/Pages/Home/LoginModal.razor b/Shogi.UI/Pages/Home/LoginModal.razor index 69120d9..8e9e5bd 100644 --- a/Shogi.UI/Pages/Home/LoginModal.razor +++ b/Shogi.UI/Pages/Home/LoginModal.razor @@ -22,8 +22,8 @@

How would you like to proceed?

- - + + @if (AccountState.User != null) { /* This is an escape hatch in case user login fails in certain ways. */