Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter Web Login #1

Closed
nomanmurtaza786 opened this issue Jul 9, 2021 · 27 comments
Closed

Flutter Web Login #1

nomanmurtaza786 opened this issue Jul 9, 2021 · 27 comments
Labels
auth This issue or pull request is related to authentication documentation Improvements or additions to documentation

Comments

@nomanmurtaza786
Copy link

Hi there,
I am trying to integrate Supabase with the flutter App. I am using plugin url_strategy to remove # from the flutter URL.
https://pub.dev/packages/url_strategy/

But when I get Supabase call back it starts with # so the flutter web router also removes that URL. Is there any we can get call back URL without #?

@nomanmurtaza786 nomanmurtaza786 added the documentation Improvements or additions to documentation label Jul 9, 2021
@phamhieu
Copy link
Member

phamhieu commented Jul 9, 2021

Hi @nomanmurtaza786, using fragment # is a gotrue design choice. You can read more details here

@nomanmurtaza786
Copy link
Author

nomanmurtaza786 commented Jul 9, 2021

Hi @nomanmurtaza786, using fragment # is a gotrue design choice. You can read more details here

Actually, I am using flutter web, any guide to get a callback URL in flutter web?

@nomanmurtaza786
Copy link
Author

nomanmurtaza786 commented Jul 9, 2021

@phamhieu
Copy link
Member

Hi @nomanmurtaza786, if you want to use a custom redirect_to for flutter web. Please replace # with the encoded value %23

http://localhost:55510/%23/webAuth

Screenshot 2021-07-14 at 10 54 57 AM

I suggest you to use default Site URL for flutter web. Check out the update example here

web-demo.mp4

@nomanmurtaza786
Copy link
Author

nomanmurtaza786 commented Jul 14, 2021

Hi @nomanmurtaza786, if you want to use a custom redirect_to for flutter web. Please replace # with the encoded value %23

http://localhost:55510/%23/webAuth
Screenshot 2021-07-14 at 10 54 57 AM

I suggest you to use default Site URL for flutter web. Check out the update example here

web-demo.mp4

Thanks, @phamhieu I will try this. but do you know how can we do the auth with popup and return back to the same screen with flutter web.

@himeshp
Copy link

himeshp commented Jul 14, 2021

+1 for flutter mobile Apps.
pop up + return back,

@phamhieu
Copy link
Member

Right now supabase-flutter doesn't support popup

@nomanmurtaza786
Copy link
Author

Right now supabase-flutter doesn't support popup

@phamhieu i think it's more like flutter web guide rather than supabase. Open popup and go back when uri.base contain access token.

@phamhieu
Copy link
Member

phamhieu commented Jul 14, 2021

because of security, i don't think we can do that on flutter web or event original web app.

sorry, i misunderstand your question. Can you share more why you want to do it in a popup instead of a full page redirect?

@himeshp
Copy link

himeshp commented Jul 14, 2021

It's a better user experience at least on the flutter mobile app, it takes out all the deep linking hassle + user is already logged in e.g. Twitter, Google, FB, etc.

@nomanmurtaza786
Copy link
Author

because of security, i don't think we can do that on flutter web or event original web app.

sorry, i misunderstand your question. Can you share more why you want to do it in a popup instead of a full-page redirect?

yes exactly instead, full screen can we do it in the popup and go back to the same page.

@dshukertjr
Copy link
Member

Supporting pop up kind of like how Firebase Auth does it involves some additional development on the server side, so at the moment it cannot be supported, but it is definitely something we would want at some point.

@phamhieu Could we talk to the back end team about supporting this on gotrue? Not a must have, but would be great to have it somewhere along the line!

@himeshp
Copy link

himeshp commented Jul 14, 2021

flutter web is still evolving, the adoption is slow, but on the other hand, it would be great to see pop-up support for flutter android & iOS apps.

@nomanmurtaza786
Copy link
Author

nomanmurtaza786 commented Jul 14, 2021

Supporting pop up kind of like how Firebase Auth does it involves some additional development on the server side, so at the moment it cannot be supported, but it is definitely something we would want at some point.

@phamhieu Could we talk to the back end team about supporting this on gotrue? Not a must have, but would be great to have it somewhere along the line!

@dshukertjr I think it's nothing to do with supabase it's more like a flutter web feature like I am using web view in the phone. When my url contains access token I do navigator pop and pass url back to retrieve the session. When to do same on the Web may be with dialog box it's possible.

@nomanmurtaza786
Copy link
Author

nomanmurtaza786 commented Jul 14, 2021

flutter web is still evolving, the adoption is slow, but on the other hand, it would be great to see pop-up support for flutter android & iOS apps.

@himeshp Pop kind of thing is already happening in the phone. With webview here is code. I don't know how flutter web popup work because thing package don't support web.

Expanded(
                  child: InAppWebView(
                    initialUrlRequest: URLRequest(url: Uri.parse("https://12345supaaaaedfdsfds.supabase.co/auth/v1/authorize?provider=google")),
                    initialOptions: InAppWebViewGroupOptions(
                      crossPlatform: InAppWebViewOptions(
                          supportZoom: true,
                          userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:61.0) Gecko/20100101 Firefox/61.0"
                      ),
                    ),
                    onWebViewCreated: (InAppWebViewController controller) {
                      webView = controller;
                    },
                    onLoadStart: (controller, url) {
                      if(isFirstTime){
                        isFirstTime = false;
                        Future.delayed(Duration(milliseconds: 2000))
                            .then((onValue) {
                          setState(() {
                            _isLoading = false;
                          });
                        });
                      }
                     print(url);
                      print(controller.getUrl());
                      print('load start');
                      if(url.toString().contains('access_token')){
                        Navigator.pop(context, url.toString());
                      }
                    },
                    onLoadStop: (controller, url) async {
                      print(url);
                      print(controller.getUrl());
                      print('load stop');
                       //}
                    },

@himeshp
Copy link

himeshp commented Jul 14, 2021

I don't think so native pop-up is supported yet for mobile apps.

also as shared by @dshukertjr you might have to wait until it's supported by the backend.

@dshukertjr
Copy link
Member

dshukertjr commented Jul 14, 2021

So there seems to be two discussions about pop ups going on here:

  1. pop up login on the web
  2. pop up login on mobile app

In my previous post on this issue, I was talking about 2, because users are already logged into Google, Twitter, or whatever account they are using to sign in, which leads to better user experience as @himeshp described:

It's a better user experience at least on the flutter mobile app, it takes out all the deep linking hassle + user is already logged in e.g. Twitter, Google, FB, etc.

@nomanmurtaza786 you seem to want 1, but what is the reason why you prefer pop up over full page redirect?

Also, this pop idea using webview is cleaver, but the users would still have to sign on to their twitter or whatever provider they are trying to sign in with as it is not a native pop-up sign on. Also, Google does not seem to let you sign in from within a webview.

@himeshp Pop kind of thing is already happening in the phone. With webview here is code. I don't know how flutter web popup work because thing package don't support web.

@nomanmurtaza786
Copy link
Author

So there seems to be two discussions about pop ups going on here:

  1. pop up login on the web
  2. pop up login on mobile app

In my previous post on this issue, I was talking about 2, because users are already logged into Google, Twitter, or whatever account they are using to sign in, which leads to better user experience as @himeshp described:

It's a better user experience at least on the flutter mobile app, it takes out all the deep linking hassle + user is already logged in e.g. Twitter, Google, FB, etc.

@nomanmurtaza786 you seem to want 1, but what is the reason why you prefer pop up over full page redirect?

Also, this pop idea using webview is cleaver, but the users would still have to sign on to their twitter or whatever provider they are trying to sign in with as it is not a native pop-up sign on. Also, Google does not seem to let you sign in from within a webview.

@himeshp Pop kind of thing is already happening in the phone. With webview here is code. I don't know how flutter web popup work because thing package doesn't support web.

I want to send the user back to the same screen, I think I can pass the current page URL as a redirection parameter to do that. @phamhieu If we added one domain in the supabase setting can redirect to any sub-page of that domain?

@dshukertjr
Copy link
Member

@nomanmurtaza786 Ah, got it! If there is only one page that you would like to return to, they you can actually configure the redirect URL to go to that page like this:
Screen Shot 2021-07-15 at 7 55 34

With this, you can always make sure that the user is sent back to the login page that they originally came from! Would this be sufficient in your case?

@nomanmurtaza786
Copy link
Author

@nomanmurtaza786 Ah, got it! If there is only one page that you would like to return to, they you can actually configure the redirect URL to go to that page like this:
Screen Shot 2021-07-15 at 7 55 34

With this, you can always make sure that the user is sent back to the login page that they originally came from! Would this be sufficient in your case?

Thanks @dshukertjr yes. Can I do like that mydomain/post?id=12, mydomain/post?id=67 and so on. Or every /post?id should be there in the listing?

@phamhieu
Copy link
Member

@nomanmurtaza786 it's better to save the current post id right before calling authentication request. Then when user comes back to the app, you can read the saved post id and show its view.

@spideythewebhead

This comment was marked as off-topic.

@dshukertjr

This comment was marked as off-topic.

@spideythewebhead

This comment was marked as off-topic.

@spideythewebhead

This comment was marked as off-topic.

@himeshp himeshp mentioned this issue Jul 22, 2021
@bdlukaa bdlukaa added the auth This issue or pull request is related to authentication label Apr 17, 2022
@bdlukaa
Copy link
Collaborator

bdlukaa commented Jul 17, 2022

To redirect in a popup, we could use url_launcher's webOnlyWindowName. If we set it to _blank, a new tab would be opened. Altough opening a new tab could be an workaround, we could use this to open an actual popup, or maybe file an issue requesting this feature on url_launcher.

cc @dshukertjr

@dshukertjr
Copy link
Member

Closing this issue as the original issue where provider sign in fails when using Flutter web with url_strategy package seems to be fixed. Please feel free to reopen this if you still encounter this issue!

Vinzent03 added a commit that referenced this issue Apr 3, 2023
* Add updated url-configuration screenshot (#1)

* Add updated url-configuration screenshot

* Update README.md

* Update README.md

Co-authored-by: Vinzent <vinzentwitte@gmail.com>

* refactor: move image file

---------

Co-authored-by: Vinzent <vinzentwitte@gmail.com>
Co-authored-by: Vinzent <vinzent03@proton.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth This issue or pull request is related to authentication documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

6 participants