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
703 stars 167 forks source link

[Auth] Connection refused after google sign in #876

Closed dhutaryan closed 5 months ago

dhutaryan commented 5 months ago

Describe the bug I deployed supabase locally on my laptop. I got an error when I tried to google sign in. It appears after I select account.

ClientException with SocketException: Connection refused (OS Error: Connection refused, errno = 61), address = 127.0.0.1, port = 60922, uri=http://127.0.0.1:54321/auth/v1/token?grant_type=id_token

I looked through everything. Tried to change and set up a ton of combinations but didn't find the reason. Please, let me know if you need additional information.

final _googleSignIn = GoogleSignIn(
    clientId:
        "<ios-client-id>",
  );
try {
  final googleSignInAccount = await _googleSignIn.signIn();

  if (googleSignInAccount == null) {
    throw SignInWithGoogleFailure();
  }

  final googleAuth = await googleSignInAccount.authentication;
  final accessToken = googleAuth.accessToken;
  final idToken = googleAuth.idToken;

  if (accessToken == null) {
    throw 'No Access Token found.';
  }
  if (idToken == null) {
    throw 'No ID Token found.';
  }

  await Supabase.instance.client.auth.signInWithIdToken(
    provider: OAuthProvider.google,
    idToken: idToken,
    accessToken: accessToken,
  );
} catch (error) {
  signOut();
  throw SignInWithGoogleFailure();
}

Version (please complete the following information):

google_sign_in: ^6.2.1
supabase_flutter: ^2.3.4
dshukertjr commented 5 months ago

Hmm, I'm not entirely sure why you are getting SocketException, but could you share your config.toml file around the configuration related to Google sign-in?

dhutaryan commented 5 months ago

Sure

[auth.external.google]
enabled = true
client_id = "env(GOOGLE_CLIENT_ID)"
secret = "env(GOOGLE_CLIENT_SECRET)"
redirect_uri = "http://localhost:54321/auth/v1/callback"
# redirect_uri = "http://127.0.0.1:54321/auth/v1/callback"
# url = ""
dshukertjr commented 5 months ago

@dhutaryan It seems like you are initializing Supabase with http://127.0.0.1:54321 as the URL, but could you confirm that it's http://127.0.0.1:54321 and not http://localhost:54321?

dhutaryan commented 5 months ago

@dshukertjr do you mean that site_url = "http://127.0.0.1:3000" in auth section?

dshukertjr commented 5 months ago

@dhutaryan No, I mean what are you passing to Supabase.initializa() for the url parameter? Does the URL you pass match the value you see on the terminal after running supabase start?

dhutaryan commented 5 months ago

Ah, sorry. Yes, it's http://127.0.0.1:54321

dshukertjr commented 5 months ago

@dhutaryan That's good. Are you able to make any other API requests to the local Supabase instance from your Flutter app?

dshukertjr commented 5 months ago

Also, how are you running your Flutter app? What platform? Is it an emulator or a real device?

dhutaryan commented 5 months ago

No, I tried to get users and have the same error

image
dhutaryan commented 5 months ago

@dshukertjr from VS code on real device

dshukertjr commented 5 months ago

Okay, using a real device is the cause, and it's not a Supabase issue.

You can read this to learn how to access local host from a connected device. https://stackoverflow.com/questions/51889837/cannot-connect-to-localhost-api-from-android-app

dhutaryan commented 5 months ago

Thank you. I've solved my issue. Now I have the following error Passed nonce and nonce in id_token should either both exist or not but there is an issue already for that https://github.com/supabase/cli/issues/1847