Why Use Google Sign-In with Expo?
- Google Sign-In provides users with an easy, trusted way to log in with their Google account.
- Essential for apps that target Android or want to streamline the onboarding experience.
- Handles account creation, authentication, and even profile data—reducing user friction.
- Complies with platform login requirements on Google Play.
- Official docs: React Native Google Sign-In
Component Overview
ContinueWithGoogleButton.tsx
import React from 'react';
import { TouchableOpacity, ActivityIndicator, StyleSheet, View, Alert } from 'react-native';
import { GoogleSignin } from '@react-native-google-signin/google-signin';
import { Image } from 'expo-image';
import { AppText } from '../shared/AppText';
import { Colors, ViewStyles } from '@/src/style';
import { Spacing } from '../shared/Spacing';
import { signInWithGoogleThunk } from '@/src/store/thunks/auth-thunk';
import { useAppDispatch, useAppSelector } from '@/src/store/hooks';
// TO-DO:
// Move the web client id to env variables
GoogleSignin.configure({
webClientId: '',
});
type Props = {
buttonType?: 'Continue with Google' | 'Sign in with Google' | 'Sign up with Google' | 'Sign In';
};
export const ContinueWithGoogleButton = (props: Props) => {
const { buttonType = 'Sign in with Google' } = props;
const dispatch = useAppDispatch();
const { isSigningInWithGoogle } = useAppSelector((state) => state.loaders);
const user = useAppSelector((state) => state.user);
const handleSignIn = () => {
if (!user.name) {
return Alert.alert('Please provide your name');
}
if (!user.postalCode || user.postalCode.length !== 5) {
return Alert.alert('Please provide a valid postal code');
}
dispatch(signInWithGoogleThunk());
};
return (
<TouchableOpacity
activeOpacity={0.7}
style={[styles.button, isSigningInWithGoogle && styles.buttonDisabled]}
onPress={handleSignIn}
disabled={isSigningInWithGoogle}>
{isSigningInWithGoogle ? (
<ActivityIndicator color={Colors.White} />
) : (
<View style={ViewStyles.rowCenter}>
<Image style={styles.icon} source={require('@/assets/auth/google.png')} />
<Spacing horizontal={5} />
<AppText style={[styles.text, isSigningInWithGoogle && styles.textDisabled]}>
{buttonType}
</AppText>
</View>
)}
</TouchableOpacity>
);
};
const styles = StyleSheet.create({
button: {
backgroundColor: 'white',
borderColor: '#747775',
borderWidth: 1,
borderRadius: 4,
height: 50,
paddingHorizontal: 12,
maxWidth: 400,
minWidth: 'auto',
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'row',
shadowColor: 'rgba(60, 64, 67, 0.15)',
shadowOffset: { width: 0, height: 1 },
shadowOpacity: 0.3,
shadowRadius: 2,
},
buttonDisabled: {
backgroundColor: '#ffffff61',
borderColor: '#1f1f1f1f',
},
contentWrapper: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
width: '100%',
height: '100%',
},
icon: {
height: 20,
width: 20,
marginRight: 12,
},
text: {
fontWeight: '500',
color: '#1f1f1f',
letterSpacing: 0.25,
},
textDisabled: {
opacity: 0.38,
},
});
- ContinueWithGoogleButton is a modular component for Google authentication.
- Supports a customizable `buttonType` prop to fit different auth flows (Sign in, Sign up, Continue).
- Validates required user info (name, 5-digit postal code) before allowing sign-in.
- Uses Redux (`useAppDispatch`, `useAppSelector`) to manage state and authentication flows.
- Visual feedback: Shows an ActivityIndicator while signing in and disables the button to prevent duplicate actions.
- Styled for accessibility, reusability, and polish—leveraging StyleSheet and custom text/image components.
Key Takeaways
- Google Sign-In simplifies onboarding and authentication for users.
- Always validate user input before allowing OAuth sign-in.
- Leverage Redux for state management and to avoid race conditions.
- Show clear UI feedback (like spinners and disabled buttons) during authentication.
- Customize the button label and style for various authentication flows.
- Move sensitive data, such as web client IDs, to environment variables in production.
- Test your Google sign-in on real devices and both Android and iOS platforms for best reliability.