Describe the bug
After opening a link sent via sendSignInWithEmailLink sent seconds ago, I am getting this error
message
PlatformException(ERROR_INVALID_ACTION_CODE, The out of band code is invalid. This can happen if the code is malformed, expired, or has already been used., null)
However it seems I am able to actually sign in as printing
await FirebaseAuth.instance.currentUser().toString()outputsFirebaseUser(Instance of 'PlatformUser')rather thannull, and I am able to print thecurrentUser().displayName`.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
User should be able to successfully sign in, but without an error to terminal.
Additional context
Tried a link from the day before - it gave the above error message as expected, and currentUser() is null as expected.
Potentially related issue: https://github.com/FirebaseExtended/flutterfire/issues/1537
My code:
import 'package:package_info/package_info.dart';
Future<void> sendSignUpWithEmail(BuildContext context, email, name) async {
final PackageInfo packageInfo = await PackageInfo.fromPlatform();
try {
await FirebaseAuth.instance.sendSignInWithEmailLink(
email: email,
url: "https://xxxxxx.page.link/xxxxx",
handleCodeInApp: true,
iOSBundleID: packageInfo.packageName,
androidPackageName: packageInfo.packageName,
androidInstallIfNotAvailable: false,
androidMinimumVersion: "21",
);
} catch (e) {
print(e);
}
}
Future<bool> signUpWithEmailAndLink(
String email, String link, String name) async {
AuthResult _authResult;
final FirebaseAuth _auth = FirebaseAuth.instance;
if (!await _auth.isSignInWithEmailLink(link)) {
print("invalid signInWithEmailLink");
return false;
}
if (link != null) {
print("link: $link");
try {
_authResult = await _auth.signInWithEmailAndLink(
email: email,
link: link.toString(),
);
} catch (e) {
print("catch error: $e");
print("catch link: " + link.toString());
return false;
}
FirebaseUser user = await _auth.currentUser();
if (user != null) {
print("signed in, user != null");
// Update name in Firebase with stored name from last session
var _user = _authResult.user;
UserUpdateInfo _userUpdateInfo = UserUpdateInfo();
_userUpdateInfo.displayName = name;
await _user.updateProfile(_userUpdateInfo);
return true;
} else {
print("not signed in, user == null");
return false;
}
} else {
print("link is null");
return false;
}
}
flutter doctor:
[√] Flutter (Channel stable, v1.12.13+hotfix.5, on Microsoft Windows [Version 10.0.17763.914], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[√] Android Studio (version 3.5)
[√] VS Code (version 1.35.0)
[√] Connected device (1 available)
pubspec.yaml:
firebase_dynamic_links: ^0.5.0+9
firebase_auth: ^0.15.3
package_info: ^0.4.0+13
I'm having this problem too. Some users can login, others can't no matter what.
I have the same issue
I've found that the error only happens if you are already registered as a user. Go to the console, remove the user you are trying to login and try again. It should work.
I've found that the error only happens if you are already registered as a user. Go to the console, remove the user you are trying to login and try again. It should work.
Not my case. I confirmed the users that can't login aren't registered. Actually if i try to login with an already registered user, I can login with no problem.
Same here. Anybody found a workaround to this?
Also, I'm only using it on iOS and I don't know how to clear the cache on iOS.
I have made a comment in #1537, that probably fixes this as well.
@janniklind It's the same way I'm doing. Works most of the times, but not always.
My app close on call: result = await _firebaseAuth.signInWithEmailAndLink(email: usuario.email, link: 'https://exemple.com');
Throw Exception:
Lost connection to device.
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23c4f02e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50b97b20 objc_exception_throw + 48
2 CoreFoundation 0x00007fff23c4ee6c +[NSException raise:format:] + 188
3 Runner 0x000000010b1c3b38 +[FIRAuthExceptionUtils raiseInvalidParameterExceptionWithReason:] + 104
4 Runner 0x000000010b1a7775 -[FIRAuth internalSignInAndRetrieveDataWithEmail:link:callback:] + 181
5 Runner 0x000000010b1a856e -[FIRAuth internalSignInAndRetrieveDataWithCredential:isReauthentication:callback:] + 382
6 Runner <…>
Hey 👋
Our rework of the firebase_auth plugin as part of the FlutterFire roadmap was published over a week ago with a ton of fixes and new features. Please could you try the new version and see if this is still an issue for you? If it is then please submit a new up to date GitHub issue.
For help migrating to the new plugins please see the new migration guide: https://firebase.flutter.dev/docs/migration