~ jwt authentication

main
Peace 9 months ago
parent 3d7ae02b39
commit f98cc9dc28
  1. 10
      FluentBlazorApp/FluentBlazorApp/Services/AccountService.cs

@ -1,5 +1,8 @@
using FluentBlazorApp.DTOs;
using FluentBlazorApp.Responses;
using FluentBlazorApp.States;
using System.Net.Http;
using System.Net.Http.Headers;
using static FluentBlazorApp.Responses.CustomResponses;
namespace FluentBlazorApp.Services
@ -29,8 +32,13 @@ namespace FluentBlazorApp.Services
}
public async Task<WeatherForecastDTO[]> GetWeatherForecastsAync()
=> await _httpClient.GetFromJsonAsync<WeatherForecastDTO[]>($"{BASE_URL}/weather");
{
if (string.IsNullOrWhiteSpace(Constants.JWTToken))
return null;
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Constants.JWTToken);
return await _httpClient.GetFromJsonAsync<WeatherForecastDTO[]>($"{BASE_URL}/weather");
}
}
}

Loading…
Cancel
Save