37 lines
1.0 KiB
Plaintext
Raw Normal View History

2025-01-24 19:17:26 -03:00
@page "/counter"
@using System.Net.Http
@using System.Collections.Generic
@using System.Text.Json
@using System.Net.Http.Headers
@using Microsoft.AspNetCore.Components.Authorization
@using phronCare.UIBlazor.Services.Authorization
@inject HttpClient _httpClient
@inject AuthenticationStateProvider authenticationStateProvider
<PageTitle>Counter</PageTitle>
<h1>Counter</h1>
<p role="status">Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
private int currentCount = 0;
private async void IncrementCount()
{
currentCount++;
var customAuthStateProvider = (CustomAuthorizationProvider)authenticationStateProvider;
var token = await customAuthStateProvider.GetTokenData();
if (!string.IsNullOrWhiteSpace(token.token))
{
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", token.token);
var response = _httpClient.GetAsync("/api/Test/administradores");
}
}
}