Skip to content

Commit 226feed

Browse files
committed
fix Google Sign In crash in Expo Go simulator
1 parent 1a2bf27 commit 226feed

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

mobile/src/screens/LoginScreen.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,33 @@ import { View, Text, TextInput, TouchableOpacity, StyleSheet, Alert, KeyboardAvo
33
import { SafeAreaView } from 'react-native-safe-area-context';
44
import { Ionicons } from '@expo/vector-icons';
55
import AsyncStorage from '@react-native-async-storage/async-storage';
6-
import { GoogleSignin, statusCodes } from '@react-native-google-signin/google-signin';
76
import { colors } from '../theme/colors';
87
import { useApp } from '../context/AppContext';
98

10-
GoogleSignin.configure({
11-
webClientId: '1076957044730-mht8sbihb0d4661hprrvbjf9v4gb0njr.apps.googleusercontent.com',
12-
offlineAccess: true,
13-
});
9+
let GoogleSignin, statusCodes;
10+
try {
11+
const gs = require('@react-native-google-signin/google-signin');
12+
GoogleSignin = gs.GoogleSignin;
13+
statusCodes = gs.statusCodes;
14+
GoogleSignin.configure({
15+
webClientId: '1076957044730-mht8sbihb0d4661hprrvbjf9v4gb0njr.apps.googleusercontent.com',
16+
offlineAccess: true,
17+
});
18+
} catch (e) {
19+
GoogleSignin = null;
20+
statusCodes = {};
21+
}
1422

1523
export default function LoginScreen({ navigation }) {
1624
const [isSignUp, setIsSignUp] = useState(false);
1725
const [form, setForm] = useState({ name: '', email: '', password: '', confirm: '' });
1826
const { login } = useApp();
1927

2028
const handleGoogleSignIn = async () => {
29+
if (!GoogleSignin) {
30+
Alert.alert('Not Available', 'Google Sign In is only available in the production build.');
31+
return;
32+
}
2133
try {
2234
await GoogleSignin.hasPlayServices();
2335
const userInfo = await GoogleSignin.signIn();

0 commit comments

Comments
 (0)