Correct bunch of issues (#36)
All checks were successful
Game Ideas deploy / build-test-deploy (push) Successful in 1m28s

Reviewed-on: #36
This commit was merged in pull request #36.
This commit is contained in:
2025-04-29 23:49:11 +02:00
parent d3d16493e6
commit f3c9e1d9da
37 changed files with 246 additions and 186 deletions

View File

@@ -5,13 +5,15 @@ using System.Text.Json;
using System.Text;
using Blazored.LocalStorage;
using GameIdeas.Shared.Constants;
using Microsoft.AspNetCore.Components.Authorization;
namespace GameIdeas.BlazorApp.Services;
public class HttpClientService(
IHttpClientFactory httpClientFactory,
ILoggerFactory loggerFactory,
ILocalStorageService localStorage) : IHttpClientService
ILocalStorageService localStorage,
AuthenticationStateProvider stateProvider) : IHttpClientService
{
private readonly HttpClient httpClient = httpClientFactory.CreateClient("GameIdeas.WebAPI");
private readonly ILogger<HttpClientService> logger = loggerFactory.CreateLogger<HttpClientService>();
@@ -141,6 +143,16 @@ public class HttpClientService(
private async Task SetAuthorizationHeader()
{
var expired = await localStorage.GetItemAsStringAsync(GlobalConstants.LS_EXPIRED_STORAGE_KEY);
if (expired == null
|| (DateTime.TryParse(expired, out DateTime expiration)
&& expiration < DateTime.UtcNow))
{
await ((JwtAuthenticationStateProvider)stateProvider).NotifyUserLogoutAsync();
return;
}
var token = await localStorage.GetItemAsStringAsync(GlobalConstants.LS_AUTH_STORAGE_KEY);
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("bearer", token);