FixAuth
This commit is contained in:
@@ -20,13 +20,12 @@ namespace TechHelper.Client.HttpRepository
|
||||
private readonly ILocalStorageService _localStorageService;
|
||||
private readonly NavigationManager _navigationManager;
|
||||
|
||||
// 构造函数现在直接接收 HttpClient
|
||||
public AuthenticationClientService(HttpClient client, // <-- 修正点:直接注入 HttpClient
|
||||
public AuthenticationClientService(HttpClient client,
|
||||
AuthenticationStateProvider authenticationStateProvider,
|
||||
ILocalStorageService localStorageService,
|
||||
NavigationManager navigationManager)
|
||||
{
|
||||
_client = client; // <-- 修正点:直接赋值
|
||||
_client = client;
|
||||
_localStorageService = localStorageService;
|
||||
_stateProvider = authenticationStateProvider;
|
||||
_navigationManager = navigationManager;
|
||||
@@ -34,8 +33,6 @@ namespace TechHelper.Client.HttpRepository
|
||||
|
||||
public async Task<AuthResponseDto> LoginAsync(UserForAuthenticationDto userForAuthenticationDto)
|
||||
{
|
||||
// 移除 using (_client = _clientFactory.CreateClient("Default"))
|
||||
// _client 已经是注入的实例,直接使用它
|
||||
var reponse = await _client.PostAsJsonAsync("account/login",
|
||||
userForAuthenticationDto);
|
||||
|
||||
@@ -71,7 +68,6 @@ namespace TechHelper.Client.HttpRepository
|
||||
|
||||
public async Task<string> RefreshTokenAsync()
|
||||
{
|
||||
// 移除 using (_client = _clientFactory.CreateClient("Default"))
|
||||
var token = _localStorageService.GetItem<string>("authToken");
|
||||
var refreshToken = _localStorageService.GetItem<string>("refreshToken");
|
||||
|
||||
@@ -167,6 +163,9 @@ namespace TechHelper.Client.HttpRepository
|
||||
((AuthStateProvider)_stateProvider).NotifyUserAuthentication(
|
||||
result.Token);
|
||||
|
||||
|
||||
|
||||
|
||||
_client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(
|
||||
"bearer", result.Token);
|
||||
|
||||
|
Reference in New Issue
Block a user