< Summary

Information
Class: Syki.Front.Auth.SykiDelegatingHandler
Assembly: Front
File(s): /home/runner/work/syki/syki/Front/Auth/SykiDelegatingHandler.cs
Tag: 22_11348620282
Line coverage
0%
Covered lines: 0
Uncovered lines: 17
Coverable lines: 17
Total lines: 39
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 14
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
SendAsync()0%210140%

File(s)

/home/runner/work/syki/syki/Front/Auth/SykiDelegatingHandler.cs

#LineLine coverage
 1using System.Net;
 2using Microsoft.JSInterop;
 3using Microsoft.AspNetCore.Components;
 4using Microsoft.AspNetCore.Components.WebAssembly.Http;
 5
 6namespace Syki.Front.Auth;
 7
 08public class SykiDelegatingHandler(ILocalStorageService storage, NavigationManager nav, SykiAuthStateProvider auth) : De
 9{
 10    protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellat
 11    {
 012        request.SetBrowserRequestCredentials(BrowserRequestCredentials.Include);
 13
 014        var token = await storage.GetItemAsync("AccessToken");
 15
 016        if (token != null)
 17        {
 018            request.Headers.Add("Authorization", $"Bearer {token}");
 19        }
 20
 021        var response = await base.SendAsync(request, cancellationToken);
 22
 023        if (response.StatusCode == HttpStatusCode.Unauthorized)
 24        {
 025            await storage.RemoveItemAsync("AccessToken");
 026            auth.MarkUserAsLoggedOut();
 027            if (!nav.Uri.Equals("/"))
 028                nav.NavigateTo("/", forceLoad: true);
 29        }
 30
 031        response.Headers.TryGetValues("X-SkipUserRegister", out var skipUserRegister);
 032        await storage.SetItemAsync("SkipUserRegister", skipUserRegister?.FirstOrDefault() ?? "False");
 33
 034        response.Headers.TryGetValues("X-CrossLogin", out var crossLogin);
 035        await storage.SetItemAsync("CrossLogin", crossLogin?.FirstOrDefault() ?? "False");
 36
 037        return response;
 038    }
 39}