-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 [firebase_auth] sms code auto retrieval (auto detect and login) not working after upgrading to 0.20.0 #4916
Comments
Hi @rameshm123 |
Hello @markusaksli-nc but still it's not working. |
Is it opening up ReCaptcha or is anything relevant logged to the console? |
Can you also show some code please? |
@markusaksli-nc there is no log relevant to this issue.. |
hello @Ehesp The below code is for firebase phone auth verification void _signInWithPhoneNumber(
BuildContext context, String verificationId, String otp) async {
debugPrint("smsCode $verificationId otp $otp");
AuthCredential _authCredential = await PhoneAuthProvider.credential(
verificationId: verificationId, smsCode: otp);
FirebaseAuth.instance
.signInWithCredential(_authCredential)
.catchError((error) {
debugPrint("_signInWithPhoneNumber manual failed ${error.toString()}");
setState(() {
_isLoading = false;
});
final snackBar = SnackBar(
content: Text("Authentication Failed"),
duration: Duration(seconds: 1));
//debugPrint(error.toString());
_scaffoldKey.currentState.showSnackBar(snackBar);
}).then((value) {
// debugPrint("_signInWithPhoneNumber manual success ${value.user.uid}");
if (value != null) {
widget._users.uid = value.user.uid;
_userBloc.getUser(widget._users.phoneNumber, widget._users.uid);
setState(() {
_uid = widget._users.uid;
// _isLoading = false;
});
}
});
}
_verifyPhoneNumber(BuildContext context) async {
setState(() {
_isOTPRecieved = false;
});
String phoneNumber = "+91" + _users.phoneNumber;
debugPrint("phoneNo $phoneNumber");
final FirebaseAuth _auth = FirebaseAuth.instance;
await _auth.verifyPhoneNumber(
phoneNumber: phoneNumber,
timeout: Duration(seconds: 60),
verificationCompleted: (authCredential) =>
_verificationComplete(authCredential, context),
verificationFailed: (authException) =>
_verificationFailed(authException, context),
codeAutoRetrievalTimeout: (verificationId) =>
_codeAutoRetrievalTimeout(verificationId),
// called when the SMS code is sent
codeSent: (verificationId, [int forceResendToken]) =>
_smsCodeSent(verificationId, forceResendToken));
}
/// will get an AuthCredential object that will help with logging into Firebase.
_verificationComplete(AuthCredential authCredential, BuildContext context) {
FirebaseAuth.instance
.signInWithCredential(authCredential)
.then((authResult) {
debugPrint("_signInWithPhoneNumber auto success ${authResult.user.uid}");
_users.uid = authResult.user.uid;
debugPrint("verfication complete");
// _userBloc.getUser(_phoneNumber, _users.uid);
_userBloc.getUser(_users.phoneNumber, authResult.user.uid);
setState(() {
_uid = authResult.user.uid;
_isAutoOtp = false;
// _isLoading = false;
});
//todo navigate user to otp screen
//Navigator.of(context).pushReplacementNamed('loginOtp', arguments: _users);
});
}
_smsCodeSent(String verificationId, forceResendToken) {
setState(() {
_isLoading = false;
_isOtpSent = true;
});
// set the verification code so that we can use it to log the user in
_smsVerificationCode = verificationId;
if (_smsVerificationCode != null || _smsVerificationCode != '') {
_initializeTimer();
setState(() {
_loadingMsgIntial = "";
_isOTPRecieved = true;
});
}
debugPrint("_smsVerificationCode ${_smsVerificationCode} ");
debugPrint("verificationId ${verificationId}");
setState(() {
_currentTime = 60;
_isTimeElapse = false;
// _initializeTimer();
});
final snackBar = SnackBar(
content: Text(
"otp.new_otp_sent".tr(args: ['$_users.phoneNumber'.toString()]),
),
duration: Duration(seconds: 2),
behavior: SnackBarBehavior.floating,
);
Timer(Duration(milliseconds: 2500), () {
setState(() {
_isOtpSent = false;
_isAutoOtp = true;
});
});
// _scaffoldKey.currentState.showSnackBar(snackBar);
}
_verificationFailed(
FirebaseAuthException authException, BuildContext context) {
debugPrint("authException ${authException.message.toString()}");
setState(() {
_isLoading = false;
_isAutoOtp = false;
});
final snackBar = SnackBar(
content: Text(authException.message.toString()),
duration: Duration(seconds: 2),
);
_scaffoldKey.currentState.showSnackBar(snackBar);
}
_codeAutoRetrievalTimeout(String verificationId) {
// set the verification code so that we can use it to log the user in
debugPrint("timeout");
debugPrint("sms code auto retrieval");
setState(() {
_isLoading = false;
_smsVerificationCode = verificationId;
_isAutoOtp = false;
});
debugPrint("_codeAutoRetrievalTimeout $verificationId");
} |
Have you tested this with multiple phone numbers or just one? |
@markusaksli-nc |
There was a report of this in #4665 as well. I think I saw this as well after first enabling device verification. It might just take some time to work again. Labeling this for now. |
Hello, I have exactly the same issue. Last version of
I confirm that the issue is not device or debug/release mode dependent. Adding manually the following code into the AndroidManifest.xml does not help:
Downgrading the package version to 0.18.4+1/0.5.2 resolves the issue, but it's hard to keep it as soon as we plan to move the codebase to null-safety. EDIT: "Android Device Verification" was enabled about a month ago. Were there any additional steps required besides just enabling? Maybe |
If you have the correct SHA-256 key in firebase console then nothing else should be necessary. |
I do have it |
I have checked, every time an sms message arrives I immediately get the following in the log:
(of course ID and time differ) |
We are experiencing exactly the same after upgrade. Activated Android Device Verification API, added SHA256, updated google-services.json ... everything works except for the auto retrieval. It's a bit of a blocking thing for us, even more when we just upgraded to null safety. Any updates from anyone?
|
I also confirm, this issue is resolved by downgrading the irebase_auth: ^0.18.4+1 |
I have been suffering from the same issue then I Found a Solution: First, discuss issue why this issue is occurring: This started after #firebase ^0.18.0" because After this enabling SafetyNet is mandatory to avoid reCaptcha verification and thus auto-verification is disabled. And If we try to use google Automatic retriever API then A hash must be associated with the message. Now Solution: If you have created Your Firebase Project After December 2020 then the Firebase message is like this 667816 is your verification code for the app name.1#/##K#Aq5V this 11 digits hash is RSA256 signature based on the package name and SHA fingerPrints. PS: I am not From Firebase support what I have shared is my experience hope This would help the community. |
@a1111198 thanks for sharing. Just to confirm, does this solution works for you on firebase_auth 1.2 or similar, or did you downgrade to previous versions before null-safety? |
This solution is working for both versions before null Safety and after Null Safety. In one project I am using a version before null safety and in one I am using a version after null safety and For both working fine.
|
Do we have any update on this? |
It seems this is not a flutter specific problem: |
Which versions should I set so that i have no conflicts with |
Hey @rameshm123, I suspect this could be a problem with the android sdk upstream. The workaround until the problem is resolved is to shorten your app name on Google Playstore to around 10-15 characters. Could someone let me know if this workaround resolves the issue? |
Thanx @Shiba-Ka this solution is working |
I'm facing the same issue AND getting the same log message as above. However, my situation is peculiar. We have a Test Firebase/Flutter Project and a Live Firebase/Flutter Project for the same App. For me the Auto-Verification is working on the Test Project and not the Live Project. Here are my Firebase Plugin Versions in both of my
Rolling back to previous versions did not help. Once again, on my Test Setup, the auto-detect Is working just fine. This is so confusing. Need help! |
@adifyr Did you read this thread? firebase/firebase-android-sdk#2688 In a nutshell; shorten your app name to 10-15 characters on Playstore, and also ensure there are no special characters. |
Closing as a solution is provided, and there is nothing to action here from a Flutterfire perspective. |
You have to generate 11 character hash key for sms retrieval. See the link useful: |
Bug report
Describe the bug
after updating the firebase plugins firebase phone auth SMS code auto-detect and login not working.
SMS is receiving and also able to log in but auto code detects not working.
Steps to reproduce
Steps to reproduce the behavior:
Using these latest version to firebas plugins
Expected behavior
Need to auto detect the sms code or verificationId and logged in.
Previously it was working. After firebase plugin upgrade it is not working.
Flutter doctor
Run
flutter doctor
and paste the output below:Flutter dependencies
Run
flutter pub deps -- --style=compact
and paste the output below:The text was updated successfully, but these errors were encountered: