hello po matagal tagal napo akong nag hahanap ng solution para sa error nato.
gusto ko lang po e handle and signin auth ko
kaso nag e-error sya kapag nag input ang user nang mali tapos crash agad.
this is my code for auth:
Thank you po sa maka sagot.
gusto ko lang po e handle and signin auth ko
kaso nag e-error sya kapag nag input ang user nang mali tapos crash agad.
this is my code for auth:
Code:
class Auth {
final _auth = FirebaseAuth.instance;
Future sigin(
String signinEmail, String signinPassword, BuildContext context) async {
try {
await _auth.signInWithEmailAndPassword(
email: signinEmail, password: signinPassword);
if (!context.mounted) return;
Navigator.push(
context, MaterialPageRoute(builder: (context) => const HomePage()));
} on FirebaseAuthException catch (e) {
// Handle FirebaseAuthException
String errorMessage;
switch (e.code) {
case 'invalid-email':
errorMessage = 'Invalid Email';
break;
case 'user-disabled':
errorMessage = 'User Disabled';
break;
case 'user-not-found':
errorMessage = 'User Not Found';
break;
case 'wrong-password':
errorMessage = 'Wrong Password';
break;
default:
errorMessage = 'An error occurred during sign-in: ${e.code}';
}
showSnackbarMessage(context, errorMessage);
print('Firebase Authentication Exception: ${e.code}/////////////');
} catch (e) {
// Handle other exceptions
showSnackbarMessage(context, 'Unexpected error during sign-in: $e');
print('Unexpected Exception: $e/////////////');
}
}
}
void showSnackbarMessage(BuildContext context, String message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(message),
backgroundColor: Colors.red,
duration: const Duration(seconds: 3),
behavior: SnackBarBehavior.floating,
margin: const EdgeInsets.only(bottom: 600, right: 20, left: 20),
),
);
}
Thank you po sa maka sagot.