37 lines
1.0 KiB
Plaintext
37 lines
1.0 KiB
Plaintext
|
|
@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");
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|