/
LoginScreen.js
100 lines (92 loc) · 2.4 KB
/
LoginScreen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import React, { useState } from 'react';
import { View, TextInput, Button, StyleSheet, Text, TouchableOpacity } from 'react-native';
import { FIREBASE_AUTH } from './firebase';
import { useNavigation } from '@react-navigation/native';
import { signInWithEmailAndPassword } from 'firebase/auth';
const LoginScreen = ({ navigation }) => {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const handleLogin = () => {
signInWithEmailAndPassword(FIREBASE_AUTH, email, password)
.then(userCredential => {
const user = userCredential.user;
console.log("Logged in with", user.email);
navigation.navigate('Home')
})
.catch(error => {
alert(error.message)
})
};
// const handleLogin = () => {
// // Perform login logic here
// };
const handleSignupScreen = () => {
navigation.navigate('Signup');
};
return (
<View style={styles.container}>
<Text style={styles.title}>Cityscape</Text>
<TextInput
style={styles.input}
placeholder="Email"
onChangeText={(text) => setEmail(text)}
/>
<TextInput
style={styles.input}
placeholder="Password"
secureTextEntry
onChangeText={(text) => setPassword(text)}
/>
<TouchableOpacity style={styles.loginButton} onPress={handleLogin}>
<Text style={styles.buttonText}>Log In</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.switchButton} onPress={handleSignupScreen}>
<Text style={styles.switchButtonText}>Sign Up</Text>
</TouchableOpacity>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
padding: 16,
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 32,
},
input: {
width: '80%',
marginBottom: 16,
padding: 10,
borderWidth: 1,
borderColor: '#ccc',
},
loginButton: {
backgroundColor: '#2980b9',
paddingVertical: 12,
paddingHorizontal: 32,
borderRadius: 10,
marginBottom: 16,
},
buttonText: {
color: '#fff',
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
},
switchButton: {
paddingVertical: 12,
paddingHorizontal: 32,
},
switchButtonText: {
color: '#2980b9',
fontSize: 16,
fontWeight: 'bold',
textAlign: 'center',
},
});
export default LoginScreen;