supabase / supabase-flutter

Flutter integration for Supabase. This package makes it simple for developers to build secure and scalable products.
https://supabase.com/
MIT License
662 stars 155 forks source link

GitHub OAuth sign in fails with invalid URL #821

Closed Akash4097 closed 5 months ago

Akash4097 commented 5 months ago

Describe the bug

i am trying to integrating github oauth for authentication in my app but when i use the following code snippet(given in docs):

await supabase.auth.signInWithOAuth(
          OAuthProvider.github,
          redirectTo: kIsWeb ? null : 'io.supabase.flutter://reset-callback/',
        );

then i got the following exception:

ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(open_error, Failed to open %22%22/auth/v1/authorize?provider=github&redirect_to=io.supabase.flutter%3A%2F%2Freset-callback%2F&flow_type=pkce&code_challenge=veok_nEBkj_jY3HfthUlvBtzsuo0Ey-B97VF2i2uFjs&code_challenge_method=s256: ShellExecute error code 2, null, null)
#0      UrlLauncherApi.launchUrl (package:url_launcher_windows/src/messages.g.dart:76:7)
<asynchronous suspension>
#1      GoTrueClientSignInProvider.signInWithOAuth (package:supabase_flutter/src/supabase_auth.dart:289:20)
<asynchronous suspension>
#2      _LoginButton.build.<anonymous closure> (package:free_chat/ui/widgets/chat_header.dart:46:24)
<asynchronous suspension>

please help me what should i do here or am i miss something?

dshukertjr commented 5 months ago

Could you outline what steps you took to setup GitHub login on Supabase?

Akash4097 commented 5 months ago

Could you outline what steps you took to setup GitHub login on Supabase?

okay:


await supabase.auth.signInWithOAuth(
  Provider.github,
  redirectTo: kIsWeb ? null : 'io.supabase.flutter://reset-callback/',
);

in order to check whether authentication work or not but it failed to give the exception as mentioned in my previous post.

dshukertjr commented 5 months ago

Can you print the url property of the getOAuthSignInUrl() method like this and paste exactly what you see in the console?

final res = await getOAuthSignInUrl(
  provider: OAuthProvider.github,
  redirectTo: kIsWeb ? null : 'io.supabase.flutter://reset-callback/',
);
print(res.url);
Akash4097 commented 5 months ago

Can you print the url property of the getOAuthSignInUrl() method like this and paste exactly what you see in the console?

final res = await getOAuthSignInUrl(
  provider: OAuthProvider.github,
  redirectTo: kIsWeb ? null : 'io.supabase.flutter://reset-callback/',
);
print(res.url);

ya i got the following resutl:

INFO: 2024-01-31 14:25:42.739389:=> Github OAuth:URL ""/auth/v1/authorize?provider=github&redirect_to=io.supabase.flutter%3A%2F%2Freset-callback%2F&flow_type=pkce&code_challenge=t9FgmhU_kpeUzjWQXNEkoc7eWNwSkBWnXgns2Ncchzc&code_challenge_method=s256

dshukertjr commented 5 months ago

Okay, double-check how you are initializing Supabase. You most likely are passing "" as the Supabase URL.

Akash4097 commented 5 months ago

Okay, double-check how you are initializing Supabase. You most likely are passing "" as the Supabase URL.

ya you are right.... actually project url is not properly return from .env file...

just one more question: as i don't have production level url because my app is in developing phase right now....so what url should i give here(see in screenshot) so that it won't redirect to unknown page... supabase

dshukertjr commented 5 months ago

@Akash4097 Glad it was solved.

just one more question: as i don't have production level url because my app is in developing phase right now....so what url should i give here(see in screenshot) so that it won't redirect to unknown page...

You can ask GitHub what to enter there in your circumstance.