fix authorize
This commit is contained in:
@@ -119,9 +119,21 @@ else
|
||||
var token = dprop.TryGetProperty("token", out var t) ? t.GetString() ?? string.Empty : string.Empty;
|
||||
var refresh = dprop.TryGetProperty("refreshToken", out var r) ? r.GetString() ?? string.Empty : string.Empty;
|
||||
|
||||
// WASM 的 localStorage 在 Server Circuit 中无意义,这里不用写 localStorage。
|
||||
// WASM 的 localStorage 在 Server Circuit 中无意义,兼容auto模式写入 localStorage。
|
||||
try
|
||||
{
|
||||
await localStorage.SetItemAsync(StorageKeys.AccessToken, token);
|
||||
await localStorage.SetItemAsync(StorageKeys.RefreshToken, refresh);
|
||||
|
||||
if (AuthStateProvider is PersistentAuthenticationStateProvider provider)
|
||||
{
|
||||
provider.UpdateAuthenticationState(token);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
// 浏览器已通过 fetch 收到 Set-Cookie;强制重载使 Circuit 使用新 Cookie。
|
||||
Logger.LogInformation("登录成功,server 跳转: {ReturnUrl}", ReturnUrl);
|
||||
Logger.LogInformation($"登录成功,server 跳转: {ReturnUrl}");
|
||||
Navigation.NavigateTo(ReturnUrl ?? "/", forceLoad: true);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
}
|
||||
catch { /* 忽略网络错误,仍继续清理客户端状态 */ }
|
||||
|
||||
if (AuthStateProvider is Atomx.Admin.Client.Utils.PersistentAuthenticationStateProvider provider)
|
||||
if (AuthStateProvider is PersistentAuthenticationStateProvider provider)
|
||||
{
|
||||
await provider.MarkUserAsLoggedOut();
|
||||
}
|
||||
@@ -41,6 +41,14 @@
|
||||
var success = jsResult.ValueKind == JsonValueKind.Object && jsResult.TryGetProperty("success", out var sp) && sp.GetBoolean();
|
||||
Logger.LogInformation("Server logout result: {Success}", success);
|
||||
|
||||
try
|
||||
{
|
||||
// 清理 localStorage(如果有的话)
|
||||
await localStorage.RemoveItemAsync(StorageKeys.AccessToken);
|
||||
await localStorage.RemoveItemAsync(StorageKeys.RefreshToken);
|
||||
}
|
||||
catch { }
|
||||
|
||||
// 尽管我们可能已经处理了服务器态,强制重新加载确保 Circuit 更新
|
||||
Navigation.NavigateTo("/account/login", forceLoad: true);
|
||||
}
|
||||
|
||||
@@ -32,17 +32,9 @@
|
||||
<Flex Justify="FlexJustify.SpaceBetween">
|
||||
帐号列表
|
||||
<div>
|
||||
<AuthorizePermissionView Permission="@Permissions.User.Create">
|
||||
<AuthorizeCheck Permission="@Permissions.Admin.Create">\
|
||||
<Button Class="me-3" OnClick="OnCreateClick" Type="ButtonType.Primary">新增</Button>
|
||||
</AuthorizePermissionView>
|
||||
@* <AuthorizeView Policy="@Permissions.Admin.Edit">
|
||||
<Authorized>
|
||||
<Button Class="me-3" OnClick="OnCreateClick" Type="ButtonType.Primary">新增</Button>
|
||||
</Authorized>
|
||||
<NotAuthorized>
|
||||
没有权限
|
||||
</NotAuthorized>
|
||||
</AuthorizeView> *@
|
||||
</AuthorizeCheck>
|
||||
</div>
|
||||
</Flex>
|
||||
</TitleTemplate>
|
||||
@@ -182,7 +174,7 @@
|
||||
{
|
||||
|
||||
loadQueryString();
|
||||
LoadList();
|
||||
_ = LoadList();
|
||||
|
||||
base.OnParametersSet();
|
||||
}
|
||||
@@ -213,28 +205,34 @@
|
||||
}
|
||||
|
||||
|
||||
private async void LoadList()
|
||||
private async Task LoadList()
|
||||
{
|
||||
|
||||
loading = true;
|
||||
var url = "/api/admin/search";
|
||||
var apiResult = await HttpService.GetPagingList<Admin>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
|
||||
if (apiResult.Success)
|
||||
try
|
||||
{
|
||||
if (apiResult.Data != null)
|
||||
var apiResult = await HttpService.GetPagingList<Admin>(url, search, Page.GetValueOrDefault(1), PageSize.GetValueOrDefault(20));
|
||||
if (apiResult.Success)
|
||||
{
|
||||
PagingList = apiResult.Data;
|
||||
if (apiResult.Data != null)
|
||||
{
|
||||
PagingList = apiResult.Data;
|
||||
}
|
||||
}
|
||||
}
|
||||
loading = false;
|
||||
StateHasChanged();
|
||||
finally
|
||||
{
|
||||
loading = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void OnReset()
|
||||
{
|
||||
search = new();
|
||||
LoadList();
|
||||
_ = LoadList();
|
||||
}
|
||||
|
||||
void OnSearchReset()
|
||||
@@ -298,7 +296,7 @@
|
||||
var apiResult = await HttpService.Post<ApiResult<string>>(url, new());
|
||||
if (apiResult.Success)
|
||||
{
|
||||
LoadList();
|
||||
_ = LoadList();
|
||||
await ModalService.InfoAsync(new ConfirmOptions() { Title = "操作提示", Content = "删除数据成功" });
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user