< Summary

Information
Class: RaidLoop.Client.Components.AuthGate
Assembly: RaidLoop.Client
File(s): /home/runner/work/RaidLoop/RaidLoop/src/RaidLoop.Client/Components/AuthGate.razor
Line coverage
0%
Covered lines: 0
Uncovered lines: 33
Coverable lines: 33
Total lines: 93
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
BuildRenderTree(...)0%7280%
get_ChildContent()100%210%
.ctor()100%210%
OnInitializedAsync()100%210%
SignInWithGoogleAsync()100%210%
SignInWithEmailPasswordAsync()100%210%
SignUpWithEmailPasswordAsync()100%210%
HandleAuthStateChanged()100%210%
Dispose()100%210%

File(s)

/home/runner/work/RaidLoop/RaidLoop/src/RaidLoop.Client/Components/AuthGate.razor

#LineLine coverage
 1@inject RaidLoop.Client.Services.SupabaseAuthService AuthService
 2@inject Microsoft.AspNetCore.Components.WebAssembly.Hosting.IWebAssemblyHostEnvironment HostEnvironment
 3@implements IDisposable
 4
 05@if (AuthService.IsLoading)
 6{
 7    <p>Checking login...</p>
 8}
 09else if (!AuthService.IsAuthenticated)
 10{
 11    <section class="panel">
 12        <h2>Login Required</h2>
 13        <p>Sign in to load your account and play.</p>
 014        @if (HostEnvironment.Environment == "Local")
 15        {
 16            <button class="action" @onclick="SignInWithGoogleAsync">Sign in with Google</button>
 17            <input @bind="_email" type="email" placeholder="Email" />
 18            <input @bind="_password" type="password" placeholder="Password" />
 19            <div class="actions">
 20                <button class="action" @onclick="SignInWithEmailPasswordAsync">Sign in</button>
 21                <button class="action" @onclick="SignUpWithEmailPasswordAsync">Sign up</button>
 22            </div>
 23        }
 24        else
 25        {
 26            <button class="action" @onclick="SignInWithGoogleAsync">Sign in with Google</button>
 27        }
 028        @if (!string.IsNullOrWhiteSpace(_authErrorMessage))
 29        {
 030            <p>@_authErrorMessage</p>
 31        }
 32    </section>
 33}
 34else
 35{
 036    @ChildContent
 37}
 38
 39@code {
 040    [Parameter] public RenderFragment? ChildContent { get; set; }
 41
 042    private string _email = string.Empty;
 043    private string _password = string.Empty;
 44    private string? _authErrorMessage;
 45
 46    protected override async Task OnInitializedAsync()
 47    {
 048        AuthService.AuthStateChanged += HandleAuthStateChanged;
 049        await AuthService.InitializeAsync();
 050    }
 51
 52    private async Task SignInWithGoogleAsync()
 53    {
 054        _authErrorMessage = null;
 055        await AuthService.SignInWithGoogleAsync();
 056    }
 57
 58    private async Task SignInWithEmailPasswordAsync()
 59    {
 60        try
 61        {
 062            _authErrorMessage = null;
 063            await AuthService.SignInWithEmailPasswordAsync(_email, _password);
 064        }
 065        catch (Exception ex)
 66        {
 067            _authErrorMessage = ex.Message;
 068        }
 069    }
 70
 71    private async Task SignUpWithEmailPasswordAsync()
 72    {
 73        try
 74        {
 075            _authErrorMessage = null;
 076            await AuthService.SignUpWithEmailPasswordAsync(_email, _password);
 077        }
 078        catch (Exception ex)
 79        {
 080            _authErrorMessage = ex.Message;
 081        }
 082    }
 83
 84    private void HandleAuthStateChanged()
 85    {
 086        _ = InvokeAsync(StateHasChanged);
 087    }
 88
 89    public void Dispose()
 90    {
 091        AuthService.AuthStateChanged -= HandleAuthStateChanged;
 092    }
 93}