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

56 messages · Page 1 of 1 (latest)

delicate linden
#

Hi. In my app, the login screen doesn't close automatically after a successfully login. I have already setup AndroidManifest.xml as below:

            <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-63f..............0" />
            </intent-filter>
        </activity>```

Project ID is correct. After user login with google, the webview shows "Missing Redirect URL"... and then it shows the login page again. Despite of that, the app continues the execution of code after the first login.

The account and session are successfully created in the server, but the webview remains open. I can run `Account(client).get()` after that. The only issue is that the page "Missing Redirect URL" appears instead of the webview closing and returning to the application.

I have the server version 1.2.1 and flutter version 8.2.2. I've tried changing the plugin version in flutter down until 8.0.0, but the error still persists.
oak pivot
delicate linden
#

The google login page. Called by await account.createOAuth2Session( provider: 'google', );

The redirect url is setup in the google app configuration, and I think it's right otherwise the user wouldn't be created in the server.

oak pivot
oak pivot
delicate linden
delicate linden
#

As you can see in the video, I had to tap to close the screen. If I tap in my email again the same things will happen in loop.

oak pivot
# delicate linden

there's nowhere else in your code where you call account.createOAuth2Session()?

Maybe you can set a breakpoint at that log("Success") and see when it's being hit?

delicate linden
oak pivot
delicate linden
#

no problem, the breakpoint was hit when appeared "Missing redirect url"

oak pivot
delicate linden
#

It's a very big project, I would have to create a new project with minimum reproducible code.

oak pivot
delicate linden
#

ok I'll try it

#

here is almost midnight, tomorrow I tell you the results.

delicate linden
#

Ok, I'm able to reproduce the same error in the playground.

  1. First of all, I upgraded dart dependencies to:
appwrite: ^8.2.2
file_picker: ^5.2.5
  1. I made 3 fixes in AndroidManifest.xml, changed flutter_web_auth to flutter_web_auth_2 (twice) and put android:exported="true".

  2. (You can just ignore): I put my project credentials and changed my package name in gradle.

Then I executed the project, and I logged into my account. After successfully login, the flutter activity was open again with my name in the screen. It seems right, but when you close the flutter activity you will see the login page again, that shouldn't be there.

So I realized the diference between the playground and my project. In AndroidManifest.xml my main activity is android:launchMode="singleInstance" and playground is android:launchMode="singleTop". When I changed the launchMode in the Playground, I have exact same bug as my previous video.

In both situations, a bug will happen. When singleTop, the webview keeps open but in background, it will appear again when exiting flutter by pressing android back button. When singleInstance the webview will remain on top.

#

The webview is not being closed anyway.

oak pivot
delicate linden
#

Just by pressing android navigation back button

oak pivot
delicate linden
oak pivot
delicate linden
#

I sent to you in DM, because I included server private info

delicate linden
#
[✓] Flutter (Channel stable, 3.7.5, on macOS 13.1 22C65 darwin-arm64, locale en-BR)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.75.1)
[✓] Connected device (3 available)
[✓] HTTP Host Availability
#

I'll try downgrade my flutter version to yours 3.3.9

delicate linden
#

Same bug, I really don't have any ideia now. I think I'll have to setup everything from scratch

delicate linden
#

You right, it’s best I try that first

oak pivot
#

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

delicate linden
#
[✓] 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.
#

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.

oak pivot
delicate linden
#

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

oak pivot
#

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

unreal dagger
delicate linden
#

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

unreal dagger
oblique shore
#

@oak pivot @delicate linden do sent me the server details if you want me to test it out

#

I couldn't reproduce on my server

delicate linden
#

@oak pivot 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

@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:

var platform = MethodChannel('my_platform/channel');
platform.invokeMethod('backToApp');
oak pivot
#

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

delicate linden
#

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

oak pivot
delicate linden
#

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

oak pivot
delicate linden
#

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.

oak pivot
unreal dagger
oblique shore