2025-11-06 10:20:00 +01:00
|
|
|
|
|
|
|
|
@using DiunaBI.UI.Shared.Services
|
|
|
|
|
@using Microsoft.Extensions.Configuration
|
|
|
|
|
@inject IJSRuntime JS
|
|
|
|
|
@inject IConfiguration Configuration
|
|
|
|
|
@inject AuthService AuthService
|
|
|
|
|
@inject NavigationManager NavigationManager
|
|
|
|
|
|
|
|
|
|
<MudCard Class="login-card" Elevation="8">
|
|
|
|
|
<MudCardContent Class="pa-8 d-flex flex-column align-center">
|
2025-11-09 19:39:52 +01:00
|
|
|
<MudText Typo="Typo.h4" Class="mb-4">Witaj w DiunaBI</MudText>
|
2025-11-06 10:20:00 +01:00
|
|
|
<MudText Typo="Typo.body1" Class="mb-6 text-center">
|
|
|
|
|
Zaloguj się używając konta Google
|
|
|
|
|
</MudText>
|
|
|
|
|
|
|
|
|
|
<MudButton
|
|
|
|
|
Variant="Variant.Filled"
|
|
|
|
|
StartIcon="@Icons.Custom.Brands.Google"
|
|
|
|
|
Size="Size.Large"
|
|
|
|
|
OnClick="HandleGoogleSignIn"
|
|
|
|
|
Disabled="@_isLoading">
|
|
|
|
|
@if (_isLoading)
|
|
|
|
|
{
|
|
|
|
|
<MudProgressCircular Class="mr-3" Size="Size.Small" Indeterminate="true"></MudProgressCircular>
|
2025-11-09 19:39:52 +01:00
|
|
|
<span>Weryfikacja...</span>
|
2025-11-06 10:20:00 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<span>Zaloguj z Google</span>
|
|
|
|
|
}
|
|
|
|
|
</MudButton>
|
|
|
|
|
|
|
|
|
|
@if (!string.IsNullOrEmpty(_errorMessage))
|
|
|
|
|
{
|
2025-11-09 19:39:52 +01:00
|
|
|
<MudAlert Severity="Severity.Error" Class="mt-4" Dense="true">
|
2025-11-06 10:20:00 +01:00
|
|
|
@_errorMessage
|
|
|
|
|
</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
</MudCardContent>
|
|
|
|
|
</MudCard>
|
|
|
|
|
|
|
|
|
|
@code {
|
|
|
|
|
private bool _isLoading = false;
|
|
|
|
|
private string _errorMessage = string.Empty;
|
|
|
|
|
private static LoginCard? _instance;
|
|
|
|
|
private bool _isInitialized = false;
|
|
|
|
|
|
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
|
|
|
{
|
|
|
|
|
if (firstRender)
|
|
|
|
|
{
|
|
|
|
|
_instance = this;
|
|
|
|
|
await InitializeGoogleSignIn();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task InitializeGoogleSignIn()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (_isInitialized) return;
|
2025-11-19 12:33:37 +01:00
|
|
|
|
2025-11-06 10:20:00 +01:00
|
|
|
var clientId = Configuration["GoogleAuth:ClientId"];
|
2025-11-19 12:33:37 +01:00
|
|
|
Console.WriteLine($"🔍 Reading GoogleAuth:ClientId from configuration: '{clientId}'");
|
|
|
|
|
|
2025-11-06 10:20:00 +01:00
|
|
|
if (string.IsNullOrEmpty(clientId))
|
|
|
|
|
{
|
2025-11-19 12:33:37 +01:00
|
|
|
_errorMessage = "Google ClientId is not configured in appsettings.";
|
|
|
|
|
Console.Error.WriteLine("❌ Google ClientId is NULL or EMPTY in configuration!");
|
|
|
|
|
return;
|
2025-11-06 10:20:00 +01:00
|
|
|
}
|
|
|
|
|
|
2025-11-19 12:33:37 +01:00
|
|
|
Console.WriteLine($"✅ Calling initGoogleSignIn with clientId: {clientId}");
|
2025-11-06 10:20:00 +01:00
|
|
|
await JS.InvokeVoidAsync("initGoogleSignIn", clientId);
|
|
|
|
|
_isInitialized = true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_errorMessage = "Błąd inicjalizacji Google Sign-In.";
|
2025-11-19 12:33:37 +01:00
|
|
|
Console.Error.WriteLine($"❌ Google Sign-In initialization error: {ex.Message}");
|
|
|
|
|
Console.Error.WriteLine($"Stack trace: {ex.StackTrace}");
|
2025-11-06 10:20:00 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task HandleGoogleSignIn()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
_errorMessage = string.Empty;
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
|
|
|
|
|
await JS.InvokeVoidAsync("requestGoogleSignIn");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_errorMessage = "Błąd podczas logowania. Spróbuj ponownie";
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JSInvokable]
|
2025-11-09 19:39:52 +01:00
|
|
|
public static async Task OnGoogleSignInSuccess(string googleCredential, string fullName, string email, string avatarUrl)
|
2025-11-06 10:20:00 +01:00
|
|
|
{
|
2025-11-09 19:39:52 +01:00
|
|
|
Console.WriteLine($"=== OnGoogleSignInSuccess: {email} ===");
|
2025-11-06 10:20:00 +01:00
|
|
|
|
|
|
|
|
if (_instance != null)
|
|
|
|
|
{
|
2025-11-09 19:39:52 +01:00
|
|
|
try
|
2025-11-06 10:20:00 +01:00
|
|
|
{
|
2025-11-09 19:39:52 +01:00
|
|
|
// Waliduj użytkownika w backendzie DiunaBI
|
|
|
|
|
var (success, errorMessage) = await _instance.AuthService.ValidateWithBackendAsync(
|
|
|
|
|
googleCredential, fullName, email, avatarUrl);
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("✅ User validated, navigating to dashboard");
|
|
|
|
|
_instance._isLoading = false;
|
|
|
|
|
_instance._errorMessage = string.Empty;
|
|
|
|
|
_instance.NavigationManager.NavigateTo("/dashboard", replace: true);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"❌ Validation failed: {errorMessage}");
|
|
|
|
|
_instance._isLoading = false;
|
|
|
|
|
_instance._errorMessage = errorMessage ?? "Nie udało się zalogować.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await _instance.InvokeAsync(() => _instance.StateHasChanged());
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.Error.WriteLine($"❌ OnGoogleSignInSuccess error: {ex.Message}");
|
|
|
|
|
_instance._isLoading = false;
|
|
|
|
|
_instance._errorMessage = "Błąd podczas weryfikacji użytkownika.";
|
|
|
|
|
await _instance.InvokeAsync(() => _instance.StateHasChanged());
|
|
|
|
|
}
|
2025-11-06 10:20:00 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JSInvokable]
|
|
|
|
|
public static async Task OnGoogleSignInError(string error)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Google SignIn Error: {error}");
|
|
|
|
|
|
|
|
|
|
if (_instance != null)
|
|
|
|
|
{
|
|
|
|
|
_instance._isLoading = false;
|
|
|
|
|
_instance._errorMessage = "Błąd logowania Google. Spróbuj ponownie";
|
|
|
|
|
await _instance.InvokeAsync(() => _instance.StateHasChanged());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.login-card {
|
|
|
|
|
max-width: 400px;
|
|
|
|
|
width: 100%;
|
|
|
|
|
background: rgba(255, 255, 255, 0.95);
|
|
|
|
|
backdrop-filter: blur(10px);
|
|
|
|
|
}
|
|
|
|
|
</style>
|