diff --git a/FluentBlazorApp/FluentBlazorApp/Services/AccountService.cs b/FluentBlazorApp/FluentBlazorApp/Services/AccountService.cs index f488d9b..18921b5 100644 --- a/FluentBlazorApp/FluentBlazorApp/Services/AccountService.cs +++ b/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 GetWeatherForecastsAync() - => await _httpClient.GetFromJsonAsync($"{BASE_URL}/weather"); + { + if (string.IsNullOrWhiteSpace(Constants.JWTToken)) + return null; + _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Constants.JWTToken); + return await _httpClient.GetFromJsonAsync($"{BASE_URL}/weather"); + } } }