Files
ExemploAppMAUI/GuilhermesApp/Pages/LoginPage.xaml.cs
Guilherme Gaspar 44f456eb29 Guilhermes
2026-03-23 17:42:36 +00:00

42 lines
1.3 KiB
C#

using GuilhermesApp.Helpers;
namespace GuilhermesApp.Pages;
public partial class LoginPage : ContentPage
{
private FirebaseService _firebaseService = new FirebaseService();
public LoginPage()
{
InitializeComponent();
}
private async void OnLoginClicked(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(EmailEntry.Text) || string.IsNullOrWhiteSpace(PasswordEntry.Text))
{
await DisplayAlert("Erro", "Preenche o email e a password.", "OK");
return;
}
try
{
// Tenta fazer o login no Firebase
var user = await _firebaseService.AuthClient.SignInWithEmailAndPasswordAsync(EmailEntry.Text, PasswordEntry.Text);
// Se correr bem, vai para a página de Perfil
// O "//" define a HomePage como a nova raiz e impede de voltar atrás
await Shell.Current.GoToAsync("//MainTabs");
}
catch (Exception)
{
await DisplayAlert("Erro", "Login falhou. Verifica as credenciais.", "OK");
}
}
private async void OnRegisterClicked(object sender, EventArgs e)
{
// Vai para a página de registo
await Shell.Current.GoToAsync(nameof(RegisterPage));
}
}