| | | 1 | | @inject RaidLoop.Client.Services.SupabaseAuthService AuthService |
| | | 2 | | @inject Microsoft.AspNetCore.Components.WebAssembly.Hosting.IWebAssemblyHostEnvironment HostEnvironment |
| | | 3 | | @implements IDisposable |
| | | 4 | | |
| | 0 | 5 | | @if (AuthService.IsLoading) |
| | | 6 | | { |
| | | 7 | | <p>Checking login...</p> |
| | | 8 | | } |
| | 0 | 9 | | else if (!AuthService.IsAuthenticated) |
| | | 10 | | { |
| | | 11 | | <section class="panel"> |
| | | 12 | | <h2>Login Required</h2> |
| | | 13 | | <p>Sign in to load your account and play.</p> |
| | 0 | 14 | | @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 | | } |
| | 0 | 28 | | @if (!string.IsNullOrWhiteSpace(_authErrorMessage)) |
| | | 29 | | { |
| | 0 | 30 | | <p>@_authErrorMessage</p> |
| | | 31 | | } |
| | | 32 | | </section> |
| | | 33 | | } |
| | | 34 | | else |
| | | 35 | | { |
| | 0 | 36 | | @ChildContent |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | @code { |
| | 0 | 40 | | [Parameter] public RenderFragment? ChildContent { get; set; } |
| | | 41 | | |
| | 0 | 42 | | private string _email = string.Empty; |
| | 0 | 43 | | private string _password = string.Empty; |
| | | 44 | | private string? _authErrorMessage; |
| | | 45 | | |
| | | 46 | | protected override async Task OnInitializedAsync() |
| | | 47 | | { |
| | 0 | 48 | | AuthService.AuthStateChanged += HandleAuthStateChanged; |
| | 0 | 49 | | await AuthService.InitializeAsync(); |
| | 0 | 50 | | } |
| | | 51 | | |
| | | 52 | | private async Task SignInWithGoogleAsync() |
| | | 53 | | { |
| | 0 | 54 | | _authErrorMessage = null; |
| | 0 | 55 | | await AuthService.SignInWithGoogleAsync(); |
| | 0 | 56 | | } |
| | | 57 | | |
| | | 58 | | private async Task SignInWithEmailPasswordAsync() |
| | | 59 | | { |
| | | 60 | | try |
| | | 61 | | { |
| | 0 | 62 | | _authErrorMessage = null; |
| | 0 | 63 | | await AuthService.SignInWithEmailPasswordAsync(_email, _password); |
| | 0 | 64 | | } |
| | 0 | 65 | | catch (Exception ex) |
| | | 66 | | { |
| | 0 | 67 | | _authErrorMessage = ex.Message; |
| | 0 | 68 | | } |
| | 0 | 69 | | } |
| | | 70 | | |
| | | 71 | | private async Task SignUpWithEmailPasswordAsync() |
| | | 72 | | { |
| | | 73 | | try |
| | | 74 | | { |
| | 0 | 75 | | _authErrorMessage = null; |
| | 0 | 76 | | await AuthService.SignUpWithEmailPasswordAsync(_email, _password); |
| | 0 | 77 | | } |
| | 0 | 78 | | catch (Exception ex) |
| | | 79 | | { |
| | 0 | 80 | | _authErrorMessage = ex.Message; |
| | 0 | 81 | | } |
| | 0 | 82 | | } |
| | | 83 | | |
| | | 84 | | private void HandleAuthStateChanged() |
| | | 85 | | { |
| | 0 | 86 | | _ = InvokeAsync(StateHasChanged); |
| | 0 | 87 | | } |
| | | 88 | | |
| | | 89 | | public void Dispose() |
| | | 90 | | { |
| | 0 | 91 | | AuthService.AuthStateChanged -= HandleAuthStateChanged; |
| | 0 | 92 | | } |
| | | 93 | | } |