This hook is available on iOS and Android devices and requires a native build. It will not work with Expo Go.
The useSignInWithGoogle() hook provides native Sign in with Google functionality for iOS and Android devices. It handles the ID token exchange with Clerk's backend and automatically manages the transfer flow between sign-up and sign-in.
The useSignInWithGoogle() hook returns the startGoogleAuthenticationFlow() method, which you can use to initiate the native Google authentication flow.
Metadata that can be read and set from the frontend and the backend. Once the authentication process is complete, the value of this field will be automatically copied to the created user's unsafe metadata (User.unsafeMetadata). One common use case is to collect custom information about the user during the authentication process and store it in this property. Read more about unsafe metadata.
The SignInJavaScript Icon object that was created, which holds the state of the current sign-in and provides helper methods to navigate and complete the sign-in process.
The SignUpJavaScript Icon object that was created, which holds the state of the current sign-up and provides helper methods to navigate and complete the sign-up process.
The following example demonstrates how to use the useSignInWithGoogle()Expo Icon hook to manage the Google authentication flow. Because the useSignInWithGoogle() hook automatically manages the transfer flow between sign-up and sign-in, you can use this component for both your sign-up and sign-in pages.
The following example demonstrates how to pass custom metadata that will be saved to the user's unsafe metadata during sign-up.
app/(auth)/sign-in.tsx
import { useRouter } from'expo-router'import { useSignInWithGoogle } from'@clerk/expo/google'import { Alert, Platform, TouchableOpacity, Text } from'react-native'exportdefaultfunctionSignInPage() {const { startGoogleAuthenticationFlow } =useSignInWithGoogle()constrouter=useRouter()// Only show on iOS and Androidif (Platform.OS!=='ios'&&Platform.OS!=='android') {returnnull }constonGoogleSignInPress=async () => {try {const { createdSessionId,setActive } =awaitstartGoogleAuthenticationFlow({// Add information about the user to their unsafe metadata unsafeMetadata: { referralSource:'mobile-app', signupDate:newDate().toISOString(), }, })if (createdSessionId && setActive) {// Set the created session as the active sessionawaitsetActive({ session: createdSessionId })// Once the session is set as active,// redirect the user to the home pagerouter.replace('/') } } catch (err:any) {// User canceled the sign-in flowif (err.code ==='SIGN_IN_CANCELLED'||err.code ==='-5') {return }Alert.alert('Error',err.message ||'An error occurred during Google sign-in')console.error('Sign in with Google error:',JSON.stringify(err,null,2)) } }return ( <TouchableOpacityonPress={onGoogleSignInPress}> <Text>Sign in with Google</Text> </TouchableOpacity> )}