supabase-flutter icon indicating copy to clipboard operation
supabase-flutter copied to clipboard

Flutter Deeplink İssue

Open SercanKaya0 opened this issue 3 years ago • 30 comments

Bug report

Flutter Deeplink İssue

Describe the bug

I do social login with Flutter, but after login it doesn't return to the application. I make all the adjustments as shown in the docs but it fails. The error may be caused by me, because I downloaded the Supabase demo application and tried it, there is the same problem. A clear and concise description of what the bug is.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to '…'
  2. Click on '…'
  3. Scroll down to '…'
  4. See error

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: [e.g. macOS, Windows]
  • Browser (if applies) [e.g. chrome, safari]
  • Version of supabase-js: [e.g. 6.0.2]
  • Version of Node.js: [e.g. 10.10.0]

Additional context

Add any other context about the problem here.

SercanKaya0 avatar Aug 17 '21 12:08 SercanKaya0

Hi @SercanKaya0

Do you have your code uploaded to a public repo where I can take a look at?

Also, could you confirm that you have done deep link set up as described here? https://supabase.io/docs/guides/with-flutter#setup-deep-links

dshukertjr avatar Aug 17 '21 12:08 dshukertjr

Hello Tyler, Yes, I did it step by step, there is no open repo, but if you send an e-mail, I can send you an invitation, or I can picture the codes, I can do whatever is comfortable.

Tyler @.***> şunları yazdı (17 Ağu 2021 15:38):

Hi @SercanKaya0 https://github.com/SercanKaya0 Do you have your code uploaded to a public repo where I can take a look at?

Also, could you confirm that you have done deep link set up as described here? https://supabase.io/docs/guides/with-flutter#setup-deep-links https://supabase.io/docs/guides/with-flutter#setup-deep-links — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/supabase/supabase-flutter/issues/16#issuecomment-900261229, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOK2IGSRD5FIEM63C3DOA5TT5JJ5NANCNFSM5CJX2XEA. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email.

SercanKaya0 avatar Aug 17 '21 12:08 SercanKaya0

@SercanKaya0 Sure, in that case, maybe if you could upload your code to a separate public repo, that might be the easiest!

dshukertjr avatar Aug 17 '21 13:08 dshukertjr

For you public tyler, You can find Supabase Helper in core/supabase/ https://github.com/SercanKaya0/ilango

Tyler @.***> şunları yazdı (17 Ağu 2021 16:00):

Sure, in that case, maybe if you could upload your code to a separate public repo, that might be the easiest!

SercanKaya0 avatar Aug 17 '21 13:08 SercanKaya0

@SercanKaya0 Thanks for this. Also, which platform were you using when you experienced this issue? iOS, Android, or web?

Also, which social login type did you test and did not come back to the app?

Lastly, what happens instead of coming back to the application? Does it just stay in the browser at localhost:3000?

dshukertjr avatar Aug 17 '21 13:08 dshukertjr

iOS and android

Tyler @.***> şunları yazdı (17 Ağu 2021 16:45):

Thanks for this. Also, which platform were you using when you experienced this issue? iOS, Android, or web?

SercanKaya0 avatar Aug 17 '21 14:08 SercanKaya0

Hi Tyler, i fix android just iOS don’t work

Tyler @.***> şunları yazdı (17 Ağu 2021 16:00):

Sure, in that case, maybe if you could upload your code to a separate public repo, that might be the easiest!

SercanKaya0 avatar Aug 17 '21 14:08 SercanKaya0

There is another error, ios sends the following error when social login with real device for the 2nd time

PlatformException (PlatformException(Error, Error while launching https://cccxxxx.supabase.co/auth/v1/authorize?provider=facebook&redirect_to=ilango%3A%2F%2Flogin-callback%2F, null, null))

Tyler @.***> şunları yazdı (17 Ağu 2021 16:45):

@SercanKaya0 https://github.com/SercanKaya0 Thanks for this. Also, which platform were you using when you experienced this issue? iOS, Android, or web?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/supabase/supabase-flutter/issues/16#issuecomment-900311707, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOK2IGVAKMJFYFXSMLLAUZDT5JRV5ANCNFSM5CJX2XEA. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email.

SercanKaya0 avatar Aug 17 '21 16:08 SercanKaya0

@SercanKaya0

Hi Tyler, i fix android just iOS don’t work

Great! What was the cause on Android?

So is it just Facebook login that you are testing, or are you using other login providers as well?

In addition to that, what happens when you fail to login? Does it take you to localhost:3000, or are you getting 5XX errors on browswer?

There is another error, ios sends the following error when social login with real device for the 2nd time

Could you explain in detail step by step to reproduce this?

dshukertjr avatar Aug 17 '21 22:08 dshukertjr

It was erroneous with a slight / jump of mine on the Android device.

I got the error on all social logins. I tried facebook, google and got an error.. 1 - I am attaching the error I received after logging in as an image. 2 - The first time I sign in with the real device, only error supabase-community/supabase-dart#1 happens, but if I try to login for the 2nd time, it does the same error I mentioned in the previous commit.

Tyler @.***> şunları yazdı (18 Ağu 2021 01:37):

@SercanKaya0 https://github.com/SercanKaya0 Hi Tyler, i fix android just iOS don’t work

Great! What was the cause on Android?

So is it just Facebook login that you are testing, or are you using other login providers as well?

In addition to that, what happens when you fail to login? Does it take you to localhost:3000, or are you getting 5XX errors on browswer?

There is another error, ios sends the following error when social login with real device for the 2nd time

Could you explain in detail step by step to reproduce this?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/supabase/supabase-flutter/issues/16#issuecomment-900676920, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOK2IGXZR6TJVS3IFSGFOG3T5LQDZANCNFSM5CJX2XEA. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email.

SercanKaya0 avatar Aug 18 '21 12:08 SercanKaya0

I am attaching the error I received after logging in as an image.

I can't find your error image. Can you check again @SercanKaya0.

phamhieu avatar Aug 19 '21 00:08 phamhieu

This issue is happening to a lot of people. I'd recommend to wait for supabase-community/supabase-dart#5 to be fixed to use providers.

bdlukaa avatar Aug 19 '21 00:08 bdlukaa

Hi, I see the same error when I try to use apple authentication on a iOS simulator and on a iOS device: Screenshot 2021-10-22 at 10 15 15 it seems like the redirect to supabase is somehow failing, but when I close the window the authentication was successful. Are there any updates on that issue or can I somehow help to debug it?

KirioXX avatar Oct 22 '21 09:10 KirioXX

Thanks for following up @KirioXX!

Do you happen to have a public repo that we can take a look at with this issue?

dshukertjr avatar Oct 22 '21 13:10 dshukertjr

No, sadly not it is a private project. But I'll be going to try to recreate it in a public project and come back to you.

KirioXX avatar Oct 22 '21 15:10 KirioXX

@KirioXX That would be awesome! Thank you so much for your help.

dshukertjr avatar Oct 23 '21 00:10 dshukertjr

@dshukertjr Here you go: https://github.com/KirioXX/supabase_flutter_test_apple_auth That is pretty much the same setup that I have in my private project and it throws the same exception. Please let me know if I can help with anything else.

KirioXX avatar Oct 23 '21 13:10 KirioXX

@KirioXX thank you so much for this! I am also seeing the issue on an emulator. I will try to spot the cause on my end as well.

In the meanwhile, I noticed that in the screenshot you provided, the error says it's trying to open Supabase URL that starts with http and not https. Maybe there's something there?

dshukertjr avatar Oct 25 '21 12:10 dshukertjr

Good spot @dshukertjr, I had the wrong URL there. But I see the same error with https: Screenshot 2021-10-25 at 13 54 01

KirioXX avatar Oct 25 '21 12:10 KirioXX

Wanted to add a few things that I have observed while getting the same error.

  1. If you look in the supabase admin, you can see that the last logged in date is updated, so things seem to be working on the back end side with getting the auth from Facebook.
  2. Looking that the URL that's being launched, for me it's of the form: https://[myproject].supabase.co/auth/v1/authorize?provider=facebook&redirect_to=[my app id]%3A%2F%2Flogin-callback%2F, it seems as if part of the string is URL encoded (the redirect_to) but the rest of the URL string is not. This seems to be similar to the images in previous comments.

Base on item 2, is it possible that url_launcher is tripping up because it's trying to URL encode the entire URL string and throwing an error because part of it is already encoded? I have not dug into the code yet, but will try to when I'm back at my computer

ashbressler avatar Dec 01 '21 17:12 ashbressler

I believe that it's this line in the GoTrue library that's causing the issue: https://github.com/supabase/gotrue-dart/blob/b9e8a88fedd4b7ca541d836b708d1afc27ff9bb2/lib/src/gotrue_api.dart#L308

I'll try to fork the GoTrue library and modify locally to see if it fixes the problem

ashbressler avatar Dec 01 '21 18:12 ashbressler

Had a chance to dig in a bit. It seems that (on iOS at least, I have some other issues with Android right now so I can't confirm) that when you open a browser window in app it trips up on the redirect_to not being one of the supported url_launcher URL Schemes. Meaning that the redirect is back to a custom URL like com.test://login-callback and I think the in app browser window just can't handle that. Or it's possible that the in app browser doesn't support custom URL schemes.

What I did was add the parameter forceSafariVC: false to this line https://github.com/supabase/supabase-flutter/blob/57ad86984a4044fb471d164f4042342d5f1adb66/lib/src/supabase_auth.dart#L170 and it now launches the default browser, I sign in to the provider, it then asks me to launch my app and when I click yes it's then fully logged in.

One other thing I tried was to add something like this to the info.plist, thinking that iOS was blocking the custom URL scheme, but it didn't work:

<key>LSApplicationQueriesSchemes</key>
	<array>
		<string>[my custom scheme from the redirect_to]</string>
	</array>

Not sure if this is the proper solution.

I'm happy to submit a pull request if that would be helpful.

ashbressler avatar Dec 03 '21 20:12 ashbressler

Any updates?

c0c4i avatar Jan 13 '22 10:01 c0c4i

Same problem here, +1

marcocondrache avatar Jan 13 '22 16:01 marcocondrache

I'm experiencing the same problem.

supabase-community/supabase-flutter#84

It does not return to the app only on iOS.

Jay-flow avatar Jan 25 '22 09:01 Jay-flow

Update on my solution that does not require any to supabase-flutter.

In looking at the code for signInWithProvider, I realized that it was just calling signIn, which returns the provider login URL, and then launching the web view myself.

So I changed my login with Facebook to look like:

final response = await supabase.auth.signIn(
      provider: Provider.facebook,
      options: AuthOptions(
          redirectTo: kIsWeb ? null : 'com.my.url://login-callback/'),
    );
final success = await launch(response.url!,
    webOnlyWindowName: '_self', forceSafariVC: false);

Again, not sure if this is the best solution, but it's been working well for me and I don't have to change any of the supabase libraries so I'm happier with that.

ashbressler avatar Feb 27 '22 20:02 ashbressler

One more update, so when I submitted the app using what said above it got rejected for launching the web browser and not a web view.

Looking at things again I saw that I was getting the auth messages in the debug console. So I added closeWebView() in my AuthState/onAuthenticated method and that seems to work ok.

I know the team is working on native auth flows so I think that should really help, but hopefully this works short term.

ashbressler avatar Feb 28 '22 13:02 ashbressler

@ashbressler Thx bro It's worked for me :)

The url_launcher package was updated 6.1.0 and the expression changed a little.

 GotrueSessionResponse res = await supabase.auth.signIn(
      provider: provider,
      options: AuthOptions(
        redirectTo: kIsWeb ? null : 'com.my.url://login-callback/',
      ),
    );

    if (res.url != null) {
      Uri authUri = Uri.parse(res.url!);
      await launchUrl(
        authUri,
        webOnlyWindowName: '_self',
        mode: LaunchMode.externalApplication,
      );
    }

Jay-flow avatar May 06 '22 07:05 Jay-flow

@ashbressler Thx bro It's worked for me :)

The url_launcher package was updated 6.1.0 and the expression changed a little.

 GotrueSessionResponse res = await supabase.auth.signIn(
      provider: provider,
      options: AuthOptions(
        redirectTo: kIsWeb ? null : 'com.my.url://login-callback/',
      ),
    );

    if (res.url != null) {
      Uri authUri = Uri.parse(res.url!);
      await launchUrl(
        authUri,
        webOnlyWindowName: '_self',
        mode: LaunchMode.externalApplication,
      );
    }

This method is not available for Apple login. The loading screen continues to repeat. As the answer to @ashbressler , you must exit the web view directly.

Future<void> signInWithSocial(
    Provider provider,
  ) async {
    GotrueSessionResponse res = await supabase.auth.signIn(
      provider: provider,
      options: AuthOptions(
        redirectTo: kIsWeb ? null : 'app.artcalendar://login-callback/',
      ),
    );

    if (res.url != null) {
      Uri authUri = Uri.parse(res.url!);

      try {
        await launchUrl(
          authUri,
        );
      } on PlatformException {
       // Handling iOS Error Exception
        if (Platform.isAndroid) {
          rethrow;
        }
      }

      return;
    }

    alertError(t('SOCIAL_LOGIN_FAIL'));
  }
  @override
  void onAuthenticated(Session session) async {
    if (Platform.isIOS) {
      // Exit Login Web View
      await closeInAppWebView();
    }
  }

I know this is a temporary solution, but it works right now.

The following error is printed on iOS, and this seems to be a fundamental problem. It happens when I come back to the app from the safari.

[AXRuntimeCommon] AX Lookup problem - errorCode:1100 error:Permission denied portName:'com.apple.iphone.axserver' PID:25073 (
	0   AXRuntime                           0x00000001eb56aa9c 7A975793-0055-365F-A61A-C16EF91F55E2 + 338588
	1   AXRuntime                           0x00000001eb51fe30 _AXGetPortFromCache + 704
	2   AXRuntime                           0x00000001eb52175c AXUIElementPerformFencedActionWithValue + 564
	3   UIKit                               0x0000000236395234 2EAAE3FE-BFB1-3E62-B103-6B14136D43AE + 934452
	4   libdispatch.dylib                   0x00000001c4d72e68 69DAC9C7-DDAF-318E-B068-BE596D142A2F + 7784
	5   libdispatch.dylib                   0x00000001c4d74a2c 69DAC9C7-DDAF-318E-B068-BE596D142A2F + 14892
	6   libdispatch.dylib                   0x00000001c4d7c124 69DAC9C7-DDAF-318E-B068-BE596D142A2F + 45348
	7   libdispatch.dylib                   0x00000001c4d7cc80 69DAC9C7-DDAF-318E-B068-BE596D142A2F + 48256
	8   libdispatch.dylib                   0x00000001c4d87500 69DAC9C7-DDAF-318E-B068-BE596D142A2F + 91392
	9   libsystem_pthread.dylib             0x00000002360660bc _pthread_wqthread + 288
	10  libsystem_pthread.dylib             0x0000000236065e5c start_wqthread + 8
)
[AXRuntimeCommon] AX Lookup problem - errorCode:1100 error:Permission denied portName:'com.apple.iphone.axserver' PID:25073 (
	0   AXRuntime                           0x00000001eb56aa9c 7A975793-0055-365F-A61A-C16EF91F55E2 + 338588
	1   AXRuntime                           0x00000001eb51fe30 _AXGetPortFromCache + 704
	2   AXRuntime                           0x00000001eb52175c AXUIElementPerformFencedActionWithValue + 564
	3   UIKit                               0x0000000236395234 2EAAE3FE-BFB1-3E62-B103-6B14136D43AE + 934452
	4   libdispatch.dylib                   0x00000001c4d72e68 69DAC9C7-DDAF-318E-B068-BE596D142A2F + 7784
	5   libdispatch.dylib                   0x00000001c4d74a2c 69DAC9C7-DDAF-318E-B068-BE596D142A2F + 14892
	6   libdispatch.dylib                   0x00000001c4d7c124 69DAC9C7-DDAF-318E-B068-BE596D142A2F + 45348
	7   libdispatch.dylib                   0x00000001c4d7cc80 69DAC9C7-DDAF-318E-B068-BE596D142A2F + 48256
	8   libdispatch.dylib                   0x00000001c4d87500 69DAC9C7-DDAF-318E-B068-BE596D142A2F + 91392
	9   libsystem_pthread.dylib             0x00000002360660bc _pthread_wqthread + 288
	10  libsystem_pthread.dylib             0x0000000236065e5c start_wqthread + 8
)
[AXRuntimeCommon] AX Lookup problem - errorCode:1100 error:Permission denied portName:'com.apple.iphone.axserver' PID:25073 (
	0   AXRuntime                           0x00000001eb56aa9c 7A975793-0055-365F-A61A-C16EF91F55E2 + 338588
	1   AXRuntime                           0x00000001eb51fe30 _AXGetPortFromCache + 704
	2   AXRuntime                           0x00000001eb52175c AXUIElementPerformFencedActionWithValue + 564
	3   UIKit                               0x0000000236395234 2EAAE3FE-BFB1-3E62-B103-6B14136D43AE + 934452
	4   libdispatch.dylib                   0x00000001c4d72e68 69DAC9C7-DDAF-318E-B068-BE596D142A2F + 7784
	5   libdispatch.dylib                   0x00000001c4d74a2c 69DAC9C7-DDAF-318E-B068-BE596D142A2F + 14892
	6   libdispatch.dylib                   0x00000001c4d7c124 69DAC9C7-DDAF-318E-B068-BE596D142A2F + 45348
	7   libdispatch.dylib                   0x00000001c4d7cc80 69DAC9C7-DDAF-318E-B068-BE596D142A2F + 48256
	8   libdispatch.dylib                   0x00000001c4d87500 69DAC9C7-DDAF-318E-B068-BE596D142A2F + 91392
	9   libsystem_pthread.dylib             0x00000002360660bc _pthread_wqthread + 288
	10  libsystem_pthread.dylib             0x0000000236065e5c start_wqthread + 8
)

Jay-flow avatar May 09 '22 11:05 Jay-flow

Hi Tyler, i fix android just iOS don’t work Tyler @.***> şunları yazdı (17 Ağu 2021 16:00): Sure, in that case, maybe if you could upload your code to a separate public repo, that might be the easiest!

how you fixed it? I encounter same problem.

mojtabana avatar Mar 18 '24 00:03 mojtabana