Why am I not getting a password reset email from the Firebase service? - flutter

I am trying to implement a password reset function that incorporates a SnackBar to display either success or error messages. The code shown below produces both the success message and the various error messages, as appropriate - but I never receive the password reset email from the Firebase service. I'm not sure if it's a Firebase setup issue or an issue with the code.
Future resetPassword() async {
try {
await FirebaseAuth.instance
.sendPasswordResetEmail(email: _emailController.text.trim());
_showSnackBar('Password reset link sent');
} on FirebaseAuthException catch (e) {
_showSnackBar(e.message.toString());
return;
}
}
Future<void> _showSnackBar(String msg) async {
final snackBar = SnackBar(
content: Text(msg),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}

Disregard. Code seems to work fine - problem was either with Firebase Auth service or my internet service provider last night. All good now.

Make sure to check your spam, because if did not add authorize rules in firebase then the reset link goes in spam mail.
.

Related

Flutter Firebase OTP verification fails even though both sent and entered OTP are the same

I am trying to implement OTP verification in my Flutter app using Firebase, but I am facing an issue where the verification fails even though both the sent and entered OTP are the same.
I am using the following function to verify the OTP:
void verifyOtp({
required BuildContext context,
required String verificationId,
required String userOtp,
required Function onSuccess,
}) async {
_isLoading = true;
notifyListeners();
try {
PhoneAuthCredential creds = PhoneAuthProvider.credential(
verificationId: verificationId, smsCode: userOtp);
User? user = (await _firebaseAuth.signInWithCredential(creds)).user!;
print('signwithcredential passed');
if (user != null) {
_uid = user.uid;
onSuccess();
}
} on FirebaseAuthException catch (e) {
print('failed Userotp: $userOtp');
showSnackBar(context, e.message.toString());
_isLoading = false;
notifyListeners();
}
}
The error I am getting is "FirebaseAuthException: sms code has expired please resend the verification code to verify again."
I am new to Flutter and Firebase, so any help in fixing this problem would be greatly appreciated.
Here are couple of things I have found maybe they will work:
Check the Firebase Console to ensure that the phone number being verified is correctly set up and that the SMS code is being sent to the right number.
Make sure that the phone number is being passed in the correct format.
FirebaseAuthException is being caught correctly. Make sure the message inside the catch block is being logged or displayed to the user.
Ensure that the dependencies and packages are correctly installed and imported.
The solution is itself an error you are getting. You have to enter the code before it expire. Try to verify the otp as soon as you get the code as it's saying "I/flutter ( 9598): error on firebaseAuthexception: [firebase_auth/session-expired] The sms code has expired. Please re-send the verification code to try again. ".

How to detect if otp is autofilled in flutter or not?

In Flutter Application, I have otp screen on which there's a login button. After the otp is automatically filled, user clicks login and a loader appears and user is logged in. But what if user clicks login before the otp is filled? I want to handle this situation. What should i do in this?
Most probably you should be having a controller for the otp field. On button click check if the otp controller is empty or incomplete. If not then do further execution. Else sure message otp is incomplete.
onTap :(){
if(otpController.text.length == 4)
{
//Process further
}
else{
//Otp isn't right
}
}
You can use Try - catch to check if credentials are correct.
try {
PhoneAuthCredential credential = PhoneAuthProvider.credential(
verificationId: verificationId,
smsCode: codeController.text.trim(),
);
UserCredential userCredential = await
_auth.signInWithCredential(credential);
}on FirebaseAuthException catch (e){
Print(e.toString());
}
if you using firebase, if otp automatically filled, that make your app authenticated. user don't need to press that button at all,your app listen to authStateChanges() and should update ui, and i assume your entire app is listen to auth state. if not, try to management that auth state in your app, using streambuilder, changenotifier, bloc management,etc. your choice.
if otp isn't there let say the user has 2 phone, and otp go in on another phone, then user should fill it manually.
Most probably you should be having a controller for the otp field. On button click check if the otp controller is empty or incomplete. If not then do further execution. Else sure message otp is incomplete.
onTap :(){
if(otpController.text.isNotEmpty || otpController.text != "")
{
//Process further
}
else{
//Otp isn't right
}
}

AWS Pinpoint events delayed and don't trigger journeys

I want to create user journey's using AWS Pinpoint. My mobile app is made with Flutter and using Amplify package to create events)
pubspec.yaml
amplify_flutter: ^0.2.4
amplify_analytics_pinpoint: ^0.2.4
I am calling this method to add the event
Future<void> logLogin(String userId) async {
await addEvent('_app.login', {PinPointAnalyticsKeys.userIdProperty: userId});
}
Future<void> addEvent(String eventName, Map<String, String> properties) async {
AnalyticsEvent event = AnalyticsEvent(eventName);
properties.forEach((key, value) {
event.properties.addStringProperty(key, value);
});
Amplify.Analytics.recordEvent(event: event);
await Amplify.Analytics.flushEvents();
}
Method handling the login:
Future<bool> performLogin(String username, String password) async {
//Code that handle login using email/password => userId
await _pinPoint.logLogin(userId);
}
My test journey: a user from a specific segment who does login should get an email right away.
I am having 2 issues:
Events get added to Pinpoint but after a delay (between 10 and 20min approximatively). Shouldn't it get added right away?
When event gets added (after the delay) no journey does get triggered, so no email sent, and the Pinpoint Journey Metrics doesn't change. What could be the reason?
Thank you all for your assistance, if I missed some details please let me know.

I can't catch the exception of Firebase Auth on flutter

I'm trying to making a signin feature on my app using firebase auth on flutter.
There are many exceptions I have to deal with but I can't catch them at all.
Here is my code.
Future<void> onSubmitted(
String email, AnimationController controller, BuildContext context) async {
controller.repeat();
FirebaseAuth _auth = FirebaseAuth.instance;
try {
_auth.signInWithEmailAndPassword(email: email, password: "1");
} on PlatformException catch (e) {
debugPrint(e.toString());
} on FirebaseAuthException catch (e) {
debugPrint(e.toString());
}
}
This is simplified form for testing. Anyway it doesn't even reach the catch statement. It raises PlatformException before it reaches the catch statement. I don't understand.
The error code is like this.
Unhandled Exception: [firebase_auth/user-not-found] There is no user record corresponding to this identifier. The user may have been deleted.
I explicitly specified the type of the exception and it's supposed to print the error message but it doesn't even reach debugPrint() function.
How should I catch the exception?
The problem was 'they were actually caught'.
There is no problem in catch statement or anywhere but the behavior of the debugger was the problem. On Android Studio I can adjust the setting so it doesn't stop when the exception raises but on VSCode, no matter what I do, it will stop when the exception is raised before the catch statement.
So if I want to continue to the next lines, I just have to click continue in the debugging toolbar.
But I really hope I can change the setting of the breaks on exceptions on VSCode as well.
According to the official FlutterFire Documentation, you should store the `UserCredential`
retrieved from method `signInWithEmailAndPassword()` object in a variable. So your code should look something like this:
try {
UserCredential userCredential = await FirebaseAuth.instance.signInWithEmailAndPassword(
email: email,
password: "1"
);
} on FirebaseAuthException catch (e) {
if (e.code == 'user-not-found') {
print('No user exists with this email.');
} else if (e.code == 'wrong-password') {
print('Incorrect Password.');
}
}
Have you done all the necessary?
Create the ios/Android apps in Firebase console
Enable the different sign-in methods (google, email, etc.)
Download the google-services.json and GoogleService-info.plist and place them in their appropriate folders
Also, _auth.signInWithEmailAndPassword(email: email, password: "1") is a async process and takes time to complete.
You need to have await
This appears to be an issue with how errors are thrown and caught when dealing with async, FlutterFire hasn't gotten around to putting theirs into try/catch yet - which we can't do anything about.
Here they discuss it: https://github.com/FirebaseExtended/flutterfire/issues/3475
Here is a pending fix: https://github.com/FirebaseExtended/flutterfire/pull/3700
At the moment the answer seems to be essentially to either step through the exceptions, or uncheck 'Uncaught exceptions' in the debugger (which is not great since it won't catch actual exceptions..)

Flutter : Sending Email

i want little ask about sending email with flutter . I using https://pub.dev/packages/flutter_email_sender#-readme-tab- for sending email.
Sending Function
Future sendEmail(String subject,String body,List<String> recipients) async{
final Email email = Email(body: body,subject: subject,recipients: recipients);
String platformResponse;
try {
await FlutterEmailSender.send(email);
platformResponse='success';
} catch (e) {
platformResponse = e.toString();
}
print(platformResponse);
}
View.dart
Center(
child: RaisedButton(
onPressed: () => _sendMail(),
child: Text('send'),
),
)
void _sendMail() async {
return await api.sendEmail(widget.namaUpdate, widget.jurusanUpdate,['zefry.reynando#gmail.com']);
}
it's possible sending email automatic without open gmail app first ? (Like in codeigniter)
i trying using another package but always open gmail app first. or this how it works?
Thanks
You're not likely to find a package that sends email out without either configuration or a visible mail client. That app would not by approved by either Apple or Google, because it might be a source of SPAM.