using System.Net.Http.Headers; namespace Biskilog_Accounting.Client.Layouts { public partial class MainLayout { protected override Task OnInitializedAsync() { CheckPermission(); return base.OnInitializedAsync(); } protected override void OnAfterRender(bool firstRender) { if (firstRender) { CheckPermission(); } base.OnAfterRender(firstRender); } private async void CheckPermission() { //Checks if user token is set else redirect user to login page if (!await m_tokenService.IsTokenSet()) { m_navigationManager.NavigateTo("/login"); } else { string token = await m_tokenService.GetToken(); var authHeader = new AuthenticationHeaderValue("Bearer", token.Substring(6).Trim()); m_http.DefaultRequestHeaders.Authorization = authHeader; } } } }