From f98cc9dc28a0bcdde01347f404a5549ed7497675 Mon Sep 17 00:00:00 2001 From: Peace Date: Mon, 5 Aug 2024 17:14:16 +0900 Subject: [PATCH] ~ jwt authentication --- .../FluentBlazorApp/Services/AccountService.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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"); + } } }