Refactor Intelligence Toolbar (#14) and fix auth regression (#24)

This PR resolves the authentication regression issue where users encountered "Unauthorized" errors after logging out and back in. This regression was identified during the refactoring of the Intelligence Toolbar.

Fixes #14

### Changes:
- **WASM Client**: Added `AuthenticationHeaderHandler` to automatically attach Bearer tokens to `HttpClient` requests.
- **Server**: Configured Cookie authentication to return `401 Unauthorized` for `/api` requests instead of redirecting to the login page.
- **Project Configuration**: Added `Microsoft.Extensions.Http` to the WASM client project to support `IHttpClientFactory` and message handlers.

Verified with local build.

Reviewed-on: #24
Co-authored-by: Marek Jasiński <jasins.marek@gmail.com>
Co-committed-by: Marek Jasiński <jasins.marek@gmail.com>
This commit was merged in pull request #24.
This commit is contained in:
2026-05-08 18:50:15 +00:00
committed by Marek Jaisński
parent 55cc3ae10d
commit 9e77aee231
8 changed files with 72 additions and 13 deletions
@@ -0,0 +1,27 @@
using System.Net.Http.Headers;
using NexusReader.Application.Abstractions.Services;
namespace NexusReader.Web.Client.Handlers;
public class AuthenticationHeaderHandler : DelegatingHandler
{
private readonly INativeStorageService _storageService;
private const string TokenKey = "nexus_auth_token";
public AuthenticationHeaderHandler(INativeStorageService storageService)
{
_storageService = storageService;
}
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var tokenResult = await _storageService.GetSecureString(TokenKey);
if (tokenResult.IsSuccess && !string.IsNullOrEmpty(tokenResult.Value))
{
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokenResult.Value);
}
return await base.SendAsync(request, cancellationToken);
}
}