'Flutter google_sign_in fail to login without code error
I have an application with google_sign_in, some users can login and others are having the following error (i don't have the full stack because it happened on release and i can't just let the app fail, so i catch it and send it to backend (yes i know is bad but ...)):
#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:597)
#1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:158)
<asynchronous suspension>
#2 MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:358)
<asynchronous suspension>
#3 GoogleSignIn._callMethod (package:google_sign_in/google_sign_in.dart:233)
<asynchronous suspension>
#4 GoogleSignIn.signIn.isCanceled (package:google_sign_in/google_sign_in.dart:361)
<asynchronous suspension>
I look at the code in (package:google_sign_in/google_sign_in.dart:361) and it fails right in:
Future<GoogleSignInAccount?> signIn() {
final Future<GoogleSignInAccount?> result =
_addMethodCall(GoogleSignInPlatform.instance.signIn, canSkipCall: true);
bool isCanceled(dynamic error) => error is PlatformException && error.code == kSignInCanceledError; <-------- IT FAILS RIGHT HERE
return result.catchError((dynamic _) => null, test: isCanceled);
}
Steps to Reproduce:
- User click to login
- User select a valid account
- Error above occurs
I am signin a user using (inside a Future and using catchError):
GoogleSignInAccount googleSignInAccount = await _googleSignIn.signIn();
Some of you might say that the user is cancelling the login BUT when a user cancel a login it throws a PlatformException with a status code 'sign_in_canceled' and i'm already catching this exception. AND i saw the error occur personally!
Additional Information:
- The SHA1 and SHA256 are correctly set (both from release key, debug and the play store).
- The google-services.json is set.
- The email are set in firebase to.
- Oauth consent is set with the icon, name, link to privacy policy.
- google_sign_in: ^5.0.1
I just need the access_token as i'm send it to my backend in Django using Allauth, as i sayed before, this error only happened with some users (they all have different android versions and devices), i tested with many different android versions and real devices, all worked fine. Because of this i needed to make a manual login (not ideal as i wanna do an one click login ...).
flutter doctor --verbose output
[✓] Flutter (Channel dev, 2.1.0-12.1.pre, on Linux, locale pt_BR.UTF-8)
• Flutter version 2.1.0-12.1.pre at /home/alexmi/snap/flutter/common/flutter
• Framework revision 8264cb3e8a (5 weeks ago), 2021-03-10 12:37:57 -0800
• Engine revision 711ab3fda0
• Dart version 2.13.0 (build 2.13.0-116.0.dev)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
• Android SDK at /home/alexmi/Android/Sdk
• Platform android-30, build-tools 30.0.0
• Java binary at: /snap/android-studio/101/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.
[✓] Chrome - develop for the web
• Chrome at google-chrome
[✓] Android Studio (version 4.1)
• Android Studio at /snap/android-studio/101/android-studio
• Flutter plugin version 55.0.1
• Dart plugin version 201.9335
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
[✓] Connected device (2 available)
• moto g 8 power (mobile) • 0069448192 • android-arm64 • Android 11 (API 30)
• Chrome (web) • chrome • web-javascript • Google Chrome 89.0.4389.114
• No issues found!
I found the solution: The problem was in the automatically login mechanism, it checks if was previously logged and then log it back, but the way i was doing this was calling it before the user actually logged in, so i thing the login action was triggered multiple times causing to be cancelled.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
