[GH-ISSUE #2444] Google sign in error Android #9197

Closed
opened 2026-04-13 04:34:48 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @KevinMartinezC on GitHub (Apr 25, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2444

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

I am implementing Google Sign-In. It works on iOS using "http://localhost:3000", but on Android, I get an error, since it does not open the account selection window. It only allows me to open the Google account selection when using the Expo IP, but Google does not allow signing in because it is a private IP. How can I make it work on Android using localhost?

I run the expo-axample as well to check it was not an issue in my implementation but it's also not working on Android just IOS

const handleLogin = async () => {
try {
console.log('Starting social sign-in...');
const response = await authClient.signIn.social(
{
provider: "google",
callbackURL: "/"
},
{
onError: (error) => {
console.log("Auth Error in callback:", error);
},
onSuccess: (data) => {
console.log("Auth Success in callback:", data);
router.replace("/(drawer)");
},
}
);

  console.log("Sign-in response:", response);
} catch (error) {
  console.error("Login error:", error);
}

};

Current vs. Expected behavior

i would expect to works for both platforms

What version of Better Auth are you using?

@better-auth/expo": "^1.2.5"

Provide environment information

- IOS 
- Android(14)

Which area(s) are affected? (Select all that apply)

Other

Auth config (if applicable)

export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "pg",
    schema: {
      ...schema,
      user: schema.members,
    },
  }),
  trustedOrigins: [env.CORS_ORIGIN, "example-app://","exp"],
  socialProviders: {
    google: {
      clientId: env.GOOGLE_CLIENT_ID,
      clientSecret: env.GOOGLE_CLIENT_SECRET,
    },
  },
  plugins: [expo()],
});

export const authClient = createAuthClient({
	baseURL: "http://localhost:3000",
	plugins: [
		expoClient({
			storagePrefix: "example-app",
			storage: SecureStore,
			scheme: "example-app"
		}),
	],
});

Additional context

No response

Originally created by @KevinMartinezC on GitHub (Apr 25, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2444 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce I am implementing Google Sign-In. It works on iOS using "http://localhost:3000", but on Android, I get an error, since it does not open the account selection window. It only allows me to open the Google account selection when using the Expo IP, but Google does not allow signing in because it is a private IP. How can I make it work on Android using localhost? I run the expo-axample as well to check it was not an issue in my implementation but it's also not working on Android just IOS const handleLogin = async () => { try { console.log('Starting social sign-in...'); const response = await authClient.signIn.social( { provider: "google", callbackURL: "/" }, { onError: (error) => { console.log("Auth Error in callback:", error); }, onSuccess: (data) => { console.log("Auth Success in callback:", data); router.replace("/(drawer)"); }, } ); console.log("Sign-in response:", response); } catch (error) { console.error("Login error:", error); } }; ### Current vs. Expected behavior i would expect to works for both platforms ### What version of Better Auth are you using? @better-auth/expo": "^1.2.5" ### Provide environment information ```bash - IOS - Android(14) ``` ### Which area(s) are affected? (Select all that apply) Other ### Auth config (if applicable) ```typescript export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", schema: { ...schema, user: schema.members, }, }), trustedOrigins: [env.CORS_ORIGIN, "example-app://","exp"], socialProviders: { google: { clientId: env.GOOGLE_CLIENT_ID, clientSecret: env.GOOGLE_CLIENT_SECRET, }, }, plugins: [expo()], }); export const authClient = createAuthClient({ baseURL: "http://localhost:3000", plugins: [ expoClient({ storagePrefix: "example-app", storage: SecureStore, scheme: "example-app" }), ], }); ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-13 04:34:48 -05:00
Author
Owner

@vinayakmalviya commented on GitHub (May 13, 2025):

As far as I know, Google does not allow localhost for callback urls for OAuth on android.

You can either:

  1. Use your device IP address on which the backend is running and register that under google oauth
  2. Use a domain name that points to your local IP or localhost (127.0.0.1)
  3. Use http://lvh.me:port or https://lvh.me:port since it always points to 127.0.0.1

In my case, I added a DNS entry in my WiFi router for the domain name api-dev.local which points to my laptop where the backend is running. Then I registered this url under google oauth - http://api-dev.local:3000/api/auth/callback/google

<!-- gh-comment-id:2875282580 --> @vinayakmalviya commented on GitHub (May 13, 2025): As far as I know, Google does not allow localhost for callback urls for OAuth on android. You can either: 1. Use your device IP address on which the backend is running and register that under google oauth 2. Use a domain name that points to your local IP or localhost (127.0.0.1) 3. Use [http://lvh.me:port](http://lvh.me) or [https://lvh.me:port](https://lvh.me) since it always points to `127.0.0.1` In my case, I added a DNS entry in my WiFi router for the domain name `api-dev.local` which points to my laptop where the backend is running. Then I registered this url under google oauth - `http://api-dev.local:3000/api/auth/callback/google`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9197