yep
This commit is contained in:
@@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
|
||||
using Shogi.UI.Pages.Home.Api;
|
||||
using Shogi.UI.Shared;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Shogi.UI.Pages.Home.Account;
|
||||
|
||||
@@ -35,21 +34,23 @@ public class AccountManager
|
||||
this.shogiSocket = shogiSocket;
|
||||
}
|
||||
|
||||
private User? MyUser { get => accountState.User; set => accountState.User = value; }
|
||||
private User? MyUser => accountState.User;
|
||||
|
||||
private Task SetUser(User user) => accountState.SetUser(user);
|
||||
|
||||
|
||||
public async Task LoginWithGuestAccount()
|
||||
{
|
||||
var response = await shogiApi.GetToken(WhichAccountPlatform.Guest);
|
||||
if (response != null)
|
||||
{
|
||||
MyUser = new User
|
||||
await SetUser(new User
|
||||
{
|
||||
DisplayName = response.DisplayName,
|
||||
Id = response.UserId,
|
||||
OneTimeSocketToken = response.OneTimeToken,
|
||||
WhichAccountPlatform = WhichAccountPlatform.Guest
|
||||
};
|
||||
await shogiSocket.OpenAsync(MyUser.Value.OneTimeSocketToken.ToString());
|
||||
});
|
||||
await shogiSocket.OpenAsync(response.OneTimeToken.ToString());
|
||||
await localStorage.SetAccountPlatform(WhichAccountPlatform.Guest);
|
||||
}
|
||||
}
|
||||
@@ -80,11 +81,12 @@ public class AccountManager
|
||||
var response = await shogiApi.GetToken(WhichAccountPlatform.Guest);
|
||||
if (response != null)
|
||||
{
|
||||
MyUser = new User(
|
||||
await accountState.SetUser(new User(
|
||||
Id: response.UserId,
|
||||
DisplayName: response.DisplayName,
|
||||
WhichAccountPlatform: WhichAccountPlatform.Guest,
|
||||
OneTimeSocketToken: response.OneTimeToken);
|
||||
WhichAccountPlatform: WhichAccountPlatform.Guest));
|
||||
await shogiSocket.OpenAsync(response.OneTimeToken.ToString());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (platform == WhichAccountPlatform.Microsoft)
|
||||
@@ -101,26 +103,21 @@ public class AccountManager
|
||||
}
|
||||
var id = state.User.Claims.Single(claim => claim.Type == "oid").Value;
|
||||
var displayName = state.User.Identity.Name;
|
||||
MyUser = new User(
|
||||
await accountState.SetUser(new User(
|
||||
Id: id,
|
||||
DisplayName: displayName,
|
||||
WhichAccountPlatform: WhichAccountPlatform.Microsoft,
|
||||
OneTimeSocketToken: response.OneTimeToken);
|
||||
WhichAccountPlatform: WhichAccountPlatform.Microsoft));
|
||||
await shogiSocket.OpenAsync(response.OneTimeToken.ToString());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (MyUser != null)
|
||||
{
|
||||
await shogiSocket.OpenAsync(MyUser.Value.OneTimeSocketToken.ToString());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task LogoutAsync()
|
||||
{
|
||||
MyUser = null;
|
||||
await accountState.SetUser(null);
|
||||
var platform = await localStorage.GetAccountPlatform();
|
||||
await localStorage.DeleteAccountPlatform();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user