sdk-for-flutter icon indicating copy to clipboard operation
sdk-for-flutter copied to clipboard

🐛 Bug Report: Google Auth screen not closing after authentication

Open TanmayOG opened this issue 1 year ago • 4 comments

👟 Reproduction steps

  1. Run the app on an Android 14 device.
  2. Initiate the Google authentication flow using the googleAuth() function.
  3. Complete the authentication process.

Dart Code:

Future<void> googleAuth() async {
  try {
    await AppwriteService.account.createOAuth2Session(
      provider: OAuthProvider.google,
    );
    loadUser();
  } on AppwriteException catch (e) {
    handleAppwriteException(e);
  } catch (e) {
    print('An unexpected error occurred: $e');
  }
}

XML:

<activity android:exported="true"
          android:name="com.linusu.flutter_web_auth_2.CallbackActivity">
          <intent-filter android:label="flutter_web_auth_2">
              <action android:name="android.intent.action.VIEW" />
              <category android:name="android.intent.category.DEFAULT" />
              <category android:name="android.intent.category.BROWSABLE" />
              <data android:scheme="appwrite-callback-[PROJECT-ID]" />
          </intent-filter>
</activity>

👍 Expected behavior

  • The authorization screen should close automatically after successful authentication.

  • User creation with OAuth should succeed without any errors.

👎 Actual Behavior

  1. The Google authorization screen remains open after authentication, requiring manual closure.

  2. The AppwriteException document_invalid_structure is thrown with the message:

Error creating user with OAuth: AppwriteException: document_invalid_structure, Invalid document structure: Unknown attribute: "userId" (400)

🎲 Appwrite version

Version 2.0.x

💻 Operating system

Windows

🧱 Your Environment

  • Flutter SDK: ^3.5.3
  • Appwrite SDK: ^13.0.0
  • OS: Windows 11
  • Testing Device: Android 14

👀 Have you spent some time to check if this issue has been raised before?

  • [x] I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

TanmayOG avatar Oct 16 '24 14:10 TanmayOG

@TanmayOG, thanks for creating this issue! 🙏🏼 Are you using Appwrite Cloud or self-hosting Appwrite?

In the XML you shared, the project ID isn't filled in:

<data android:scheme="appwrite-callback-[PROJECT-ID]" />

Did you replace the placeholder with your project ID?

stnguyen90 avatar Dec 18 '24 21:12 stnguyen90

Yes, I'm using the project ID but it is still not working

TanmayOG avatar Dec 20 '24 06:12 TanmayOG

I am not sure if it is a similar issue, But yes I am manually closing the consent screen and it doesn't redirect back to the app

patialashahi31 avatar Dec 26 '24 10:12 patialashahi31

@TanmayOG, do you have android:taskAffinity="" in your Android manifest? Maybe you can try removing it.

Reference: https://github.com/ThexXTURBOXx/flutter_web_auth_2/issues/113#issuecomment-2210791900

stnguyen90 avatar Apr 22 '25 19:04 stnguyen90

I'm having a similar issue where it redirects back to the app correctly, but the Google sign in screen is still open and "loading" behind the app. So when I close the app or go to recent apps on the phone, the window is still there.

TateWalker avatar Jul 06 '25 00:07 TateWalker

I'm having a similar issue where it redirects back to the app correctly, but the Google sign in screen is still open and "loading" behind the app. So when I close the app or go to recent apps on the phone, the window is still there.

Jk, just needed to add

options: const FlutterWebAuth2Options(
  preferEphemeral: true, // iOS
  intentFlags: ephemeralIntentFlags, // Android
)

Better documentation would be great for the available options and what they do.

TateWalker avatar Jul 06 '25 00:07 TateWalker