After almost getting Google Signin working a few months ago, I went back at it to give Android users a smoother onboarding experience in Neurture. As soon as I thought I got it working, I hit this error and thought I needed a separate google-services.json
file for my preview build (I didn’t 😅).
This guide is a result of me not finding a single point of reference for setting up Google Sign-In with Expo and Supabase. This will walk you through how to set up Google Sign-In with Expo and Supabase. It takes some inspiration from the following resources, which are each helpful but not comprehensive on their own:
Some guides above work for Firebase but I’m using Supabase 😬 Hopefully this helps you!
Note: Supabase doesn’t currently support signing in with Google on iOS so this guide is for Android only. There’s a YouTube comment from Supabase that you can see below that references a Github issue which has since been fixed. Perhaps Supabase will implement a fix for this in the future.
Create a Google Cloud Project:
tutorialGoogle
) and click Create.Enable Required APIs:
APIs & Services > Library
.Google Identity Toolkit API
.OAuth 2.0
(if not already enabled).Configure the OAuth Consent Screen:
APIs & Services > OAuth consent screen
.External
for the user type and click Create.Create OAuth 2.0 Client IDs:
For Web:
APIs & Services > Credentials
.OAuth Client ID
.Web application
as the application type.https://{YOUR_PROJECT_REFERENCE_ID}.supabase.co/auth/v1/callback
For iOS:
OAuth Client ID
.iOS
as the application type.For Android:
OAuth Client ID
.Android
as the application type.app.json
/app.config.js
/app.config.ts
file (e.g., com.myorg.myapp
).eas credentials
from the project root and selecting Android as the platform. Run this command to get the fingerprint using Expo’s command-line interface:eas credentials
preview
)preview
or production
) or use the randomly generated oneAuthentication > Providers > Google
.OAuth Client ID
from your Google Cloud console into the Authorized Client IDs
field in Supabase.Install Expo Google Sign-In:
npx expo install @react-native-google-signin/google-signin
Note: Since we’re using Supabase and Expo, you don’t need to modify the app.json
or use a google-services.json
file. This is a step you’ll find in other guides that use Firebase but you can skip that.
Update Code To Use Google Sign-In:
Auth
screen):import {
GoogleSignin,
GoogleSigninButton,
statusCodes,
} from "@react-native-google-signin/google-signin";
import { supabase } from "../yourSupabaseClient";
GoogleSignin.configure({
webClientId: <WEB_CLIENT_ID_FROM_GOOGLE_CONSOLE>,
});
const LoginComponent = () => {
const onGoogleLogin = async () => {
setLoading(true);
try {
await GoogleSignin.hasPlayServices();
const userInfo = await GoogleSignin.signIn();
const { error, data } = await supabase.auth.signInWithIdToken({
provider: "google",
token: userInfo.idToken,
});
if (!data.user) {
Alert.alert("Error signing in with Google");
return;
}
if (error) {
throw error;
}
console.log("Signed in!"); // This is where the user is signed in so do whatever you would like here
} catch (error) {
if (error.code === statusCodes.SIGN_IN_CANCELLED) {
// user cancelled the login flow
} else if (error.code === statusCodes.IN_PROGRESS) {
// operation (e.g. sign in) is in progress already
} else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
// play services not available or outdated
} else {
// some other error happened
}
} finally {
setLoading(false);
}
};
return (
<View>
{Platform.OS === "android" ? (
<>
<GoogleSigninButton
onPress={onGoogleLogin}
size={GoogleSigninButton.Size.Wide}
color={
GoogleSigninButton.Color.Dark
}
disabled={loading}
style={[styles.button]}
/>
</>
) : null}
</View>
);
};
export default SignIn;
Be sure to replace <WEB_CLIENT_ID_FROM_GOOGLE_CONSOLE>
with the ID from your web client (not your Android client) from your Google Cloud console. This part trips a lot of people up!
Build your app:
expo build:android
Test Google Sign-In using your development build.
Error: DEVELOPER_ERROR
This error often indicates a problem with the SHA-1 certificate fingerprint or the OAuth client configuration.
eas credentials
GoogleSignin.configure
call.Error: Must specify an idToken or an accessToken