Debugging live-only bug.

This commit is contained in:
2024-02-09 09:22:20 -06:00
parent 2880acb585
commit 46c8f1c3af
5 changed files with 23 additions and 34 deletions

View File

@@ -91,19 +91,4 @@ public class UserController : ControllerBase
await signOutTask;
return Ok();
}
[HttpPut("TestGuestLogout")]
public async Task<IActionResult> TestGuestLogout()
{
var signOutTask = HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
var userId = User?.GetShogiUserId();
if (!string.IsNullOrEmpty(userId))
{
connectionManager.Unsubscribe(userId);
}
await signOutTask;
return Ok();
}
}

View File

@@ -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)
{

View File

@@ -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<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
request.SetBrowserRequestCredentials(BrowserRequestCredentials.Include);
Console.WriteLine("cookie handler: {0}", request.RequestUri);
return base.SendAsync(request, cancellationToken);
}
}
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
request.SetBrowserRequestCredentials(BrowserRequestCredentials.Include);
try
{
return base.SendAsync(request, cancellationToken);
}
catch
{
Console.WriteLine("Catch!");
return base.SendAsync(request, cancellationToken);
}
}
}
}

View File

@@ -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);
}
}

View File

@@ -22,8 +22,8 @@
<div>
<p>How would you like to proceed?</p>
<p>
<button @onclick="Account.LoginWithMicrosoftAccount">Log in</button>
<button @onclick="Account.LoginWithGuestAccount">Proceed as Guest</button>
<button @onclick="async () => await Account.LoginWithMicrosoftAccount()">Log in</button>
<button @onclick="async () => await Account.LoginWithGuestAccount()">Proceed as Guest</button>
@if (AccountState.User != null)
{
/* This is an escape hatch in case user login fails in certain ways. */