Skip to content

Commit 1a2bf27

Browse files
committed
setup Google Sign In
1 parent b75609e commit 1a2bf27

4 files changed

Lines changed: 168 additions & 11 deletions

File tree

mobile/app.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"expo": {
3-
"name": "mobile",
4-
"slug": "mobile",
3+
"name": "Zappify",
4+
"slug": "zappify",
55
"version": "1.0.0",
66
"orientation": "portrait",
77
"icon": "./assets/icon.png",
@@ -13,17 +13,22 @@
1313
"backgroundColor": "#ffffff"
1414
},
1515
"ios": {
16-
"supportsTablet": true
16+
"supportsTablet": true,
17+
"bundleIdentifier": "com.zappify.app"
1718
},
1819
"android": {
1920
"adaptiveIcon": {
2021
"foregroundImage": "./assets/adaptive-icon.png",
2122
"backgroundColor": "#ffffff"
2223
},
24+
"package": "com.zappify.app",
2325
"edgeToEdgeEnabled": true
2426
},
2527
"web": {
2628
"favicon": "./assets/favicon.png"
27-
}
29+
},
30+
"plugins": [
31+
"@react-native-google-signin/google-signin"
32+
]
2833
}
2934
}

mobile/package-lock.json

Lines changed: 114 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mobile/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@
1010
},
1111
"dependencies": {
1212
"@react-native-async-storage/async-storage": "2.2.0",
13+
"@react-native-google-signin/google-signin": "^16.1.2",
1314
"@react-navigation/bottom-tabs": "^7.15.9",
1415
"@react-navigation/native": "^7.2.2",
1516
"@react-navigation/native-stack": "^7.14.10",
1617
"expo": "~54.0.33",
18+
"expo-auth-session": "~7.0.10",
19+
"expo-crypto": "~15.0.8",
1720
"expo-status-bar": "~3.0.9",
21+
"expo-web-browser": "~15.0.10",
1822
"react": "19.1.0",
1923
"react-native": "0.81.5",
2024
"react-native-gesture-handler": "~2.28.0",

mobile/src/screens/LoginScreen.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,38 @@ 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';
67
import { colors } from '../theme/colors';
78
import { useApp } from '../context/AppContext';
89

10+
GoogleSignin.configure({
11+
webClientId: '1076957044730-mht8sbihb0d4661hprrvbjf9v4gb0njr.apps.googleusercontent.com',
12+
offlineAccess: true,
13+
});
14+
915
export default function LoginScreen({ navigation }) {
1016
const [isSignUp, setIsSignUp] = useState(false);
1117
const [form, setForm] = useState({ name: '', email: '', password: '', confirm: '' });
1218
const { login } = useApp();
1319

20+
const handleGoogleSignIn = async () => {
21+
try {
22+
await GoogleSignin.hasPlayServices();
23+
const userInfo = await GoogleSignin.signIn();
24+
const user = {
25+
name: userInfo.data.user.name,
26+
email: userInfo.data.user.email,
27+
picture: userInfo.data.user.photo,
28+
};
29+
await login(user);
30+
navigation.goBack();
31+
} catch (error) {
32+
if (error.code === statusCodes.SIGN_IN_CANCELLED) return;
33+
if (error.code === statusCodes.IN_PROGRESS) return;
34+
Alert.alert('Google Sign In Failed', error.message);
35+
}
36+
};
37+
1438
const handleAuth = async () => {
1539
if (!form.email || !form.password) { Alert.alert('Error', 'Please fill all fields'); return; }
1640
if (isSignUp) {
@@ -59,6 +83,17 @@ export default function LoginScreen({ navigation }) {
5983
<Text style={styles.authBtnTxt}>{isSignUp ? 'CREATE ACCOUNT' : 'SIGN IN'}</Text>
6084
</TouchableOpacity>
6185

86+
<View style={styles.separator}>
87+
<View style={styles.sepLine} />
88+
<Text style={styles.sepTxt}>OR CONTINUE WITH</Text>
89+
<View style={styles.sepLine} />
90+
</View>
91+
92+
<TouchableOpacity style={styles.googleBtn} onPress={handleGoogleSignIn}>
93+
<Text style={styles.googleG}>G</Text>
94+
<Text style={styles.googleBtnTxt}>{isSignUp ? 'Sign up with Google' : 'Sign in with Google'}</Text>
95+
</TouchableOpacity>
96+
6297
<TouchableOpacity style={styles.switchBtn} onPress={() => setIsSignUp(!isSignUp)}>
6398
<Text style={styles.switchTxt}>
6499
{isSignUp ? 'Already have an account? ' : "Don't have an account? "}
@@ -80,6 +115,12 @@ const styles = StyleSheet.create({
80115
input: { width: '100%', borderWidth: 1.5, borderColor: colors.border, borderRadius: 12, paddingHorizontal: 16, paddingVertical: 14, fontSize: 15, color: colors.dark, marginBottom: 14 },
81116
authBtn: { width: '100%', backgroundColor: colors.brand, borderRadius: 12, paddingVertical: 16, alignItems: 'center', marginTop: 4 },
82117
authBtnTxt: { color: colors.white, fontWeight: '800', fontSize: 15, letterSpacing: 1 },
118+
separator: { flexDirection: 'row', alignItems: 'center', width: '100%', marginVertical: 16, gap: 10 },
119+
sepLine: { flex: 1, height: 1, backgroundColor: colors.border },
120+
sepTxt: { fontSize: 11, color: colors.gray, fontWeight: '600', letterSpacing: 0.5 },
121+
googleBtn: { width: '100%', flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 10, borderWidth: 1.5, borderColor: colors.border, borderRadius: 12, paddingVertical: 14 },
122+
googleG: { fontSize: 18, fontWeight: '800', color: '#4285F4' },
123+
googleBtnTxt: { fontSize: 14, fontWeight: '600', color: colors.dark },
83124
switchBtn: { marginTop: 20 },
84125
switchTxt: { fontSize: 14, color: colors.gray },
85126
switchLink: { color: colors.brand, fontWeight: '700' },

0 commit comments

Comments
 (0)