Back

[SOLVED] After login with Google the webview still open and redirecting back to a new login

  • 0
  • Flutter
Drake
2 Mar, 2023, 21:08

my emulator is running android version 13 though (api version 33). im not sure if that makes a difference

TL;DR
Title: [SOLVED] After login with Google the webview still open and redirecting back to a new login Solution: The issue was resolved by modifying the Appwrite SDK and adding "preferEphemeral: true" to the code. Additionally, a workaround was implemented by creating a method channel in MainActivity.java to open the main activity and close the webview.
fernandoxlr
3 Mar, 2023, 14:43
TypeScript
[✓] Flutter (Channel stable, 3.7.6, on macOS 13.1 22C65 darwin-arm64, locale en-BR)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.1)
[✓] VS Code (version 1.76.0)
[✓] Connected device (3 available)
[✓] HTTP Host Availability```

I've upgraded the android sdk version to last available. The error still persists.

I am testing in a real device with Android 13, and emulator with Android 13. Everything is updated. I think my last option now is uninstall everything.
fernandoxlr
3 Mar, 2023, 14:45

I sent to you in DM a video using the playground project. With everything updated. It's very strange the same code works fine in your mac and not in mine. It might be some cache here.

Drake
3 Mar, 2023, 15:14

My android sdk version is 33. I'm not sure if that makes a difference.

Also, I wonder if the memory of the emulator makes a difference...let me see how much memory I allocated

fernandoxlr
3 Mar, 2023, 15:28

I have 3gb ram and 30gb disk space in the emulator. I also tested with Android SDK 33.0.0

Drake
3 Mar, 2023, 15:30

@dlohani have you experienced this? Where if you tap back on Android, you're taken back to the oauth WebView?

squallsama
3 Mar, 2023, 16:21

Sometimes I have a similar experience

fernandoxlr
4 Mar, 2023, 13:20

@squallsama Were you able to fix it? Or just happens and stop happening?

squallsama
4 Mar, 2023, 18:22

No. It happens so rarely, so I just accepted it.

dlohani
5 Mar, 2023, 01:20

I don't think I have

dlohani
5 Mar, 2023, 01:21

@Steven @fernandoxlr do sent me the server details if you want me to test it out

dlohani
5 Mar, 2023, 01:22

I couldn't reproduce on my server

fernandoxlr
6 Mar, 2023, 15:23

@Steven I added "preferEphemeral: true", the same issue happened, but now I was able to do a workaround.

As my MainActivity is android:launchMode="singleInstance". I've created a method channel to open my main activity back. Because the preferEphemeral create the activity with FLAG_ACTIVITY_NO_HISTORY when I open my MainActivity back, the webview is closed.

So in dart, I just call the native method right after login.

MainActivity.java

TypeScript
@Override
    public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine){
        GeneratedPluginRegistrant.registerWith(flutterEngine);
        super.configureFlutterEngine(flutterEngine);

        new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL)
        .setMethodCallHandler(
          (call, result) -> {
            if (call.method.contentEquals("backToApp")){
              Intent intent = new Intent(getApplicationContext(), MainActivity.class);
              intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
              startActivity(intent);
              result.success(null);
            }
          }
        );
    }

Flutter part:

TypeScript
var platform = MethodChannel('my_platform/channel');
platform.invokeMethod('backToApp');
Drake
6 Mar, 2023, 15:48

[SOLVED] After login with Google the webview still open and redirecting back to a new login

fernandoxlr
6 Mar, 2023, 16:51

@Steven it's solved, but I had to modify the Appwrite SDK, what do you think about expose preferEphemeral to account.createOAuth2Session() ?

Drake
6 Mar, 2023, 17:42

Actually, I think you can set the property in your manifest file too...have you tried that? https://stackoverflow.com/questions/11836080/how-does-androidnohistory-true-work

fernandoxlr
6 Mar, 2023, 17:54

No, because android:noHistory="true" I have to put in the activity that will be launched. But who launches the activity is the FlutterWebAuth2 plugin

Drake
6 Mar, 2023, 17:55

Oh you mean it has to go in the WebView activity and not the flutter web auth 2 activity?

fernandoxlr
6 Mar, 2023, 17:58

Yes. First I edited AppWrite sdk to use preferEphemeral, then AppWrite sdk calls FlutterWebAuth2 authenticate method that puts NO_HISTORY to the activity of webview there. So in my project's AndroidManifest file I haven't access to that activity.

Drake
6 Mar, 2023, 18:03

@dlohani do you think it would make sense to always pass true to prefer ephemeral?

squallsama
6 Mar, 2023, 19:04

I think supabase does this. So I never faced the same issue with supabase auth(they are using web auth also)

dlohani
7 Mar, 2023, 01:28

yes, I'll have a PR

0xb4d1dea
7 Mar, 2023, 02:28

Wowo, i want to use google auth in production... Maybe i should wait to the fix XD

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more