-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoginScreen.js
189 lines (180 loc) · 4.41 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import { useNavigation } from "@react-navigation/native";
import React, { useEffect, useState } from "react";
import {
KeyboardAvoidingView,
StyleSheet,
Text,
TextInput,
TouchableOpacity,
ScrollView,
View,
} from "react-native";
import Header from "./components/Header";
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
import {
signInWithEmailAndPassword,
onAuthStateChanged,
updateProfile,
} from "firebase/auth";
import { auth } from "./firebase/firebase";
import firebase from "firebase/app";
import "firebase/auth";
const LoginScreen = () => {
const navigator = useNavigation();
const [email, setEmail] = useState(null);
const [password, setPassword] = useState(null);
// const [username, setUsername] = useState("");
useEffect(() => {
onAuthStateChanged(auth, (user) => {
if (user) {
navigator.replace("DrawerNavigator");
}
});
});
const currentUser = auth.currentUser;
const handleSignIn = () => {
signInWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
// Signed in
alert("Login Successful");
console.log(userCredential);
navigator.navigate("DrawerNavigator");
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
alert("Unable to Sign in!");
});
};
return (
<ScrollView contentContainerStyle={styles.container} behavior="padding">
<Header />
<View style={styles.inputContainer}>
<TextInput
placeholder="Email"
value={email}
onChangeText={(text) => setEmail(text)}
style={styles.input}
/>
<TextInput
placeholder="Password"
value={password}
onChangeText={(text) => setPassword(text)}
style={styles.input}
secureTextEntry
/>
</View>
<View style={styles.buttonContainer}>
<View
style={{
flex: 1,
flexDirection: "row",
justifyContent: "center",
alignItems: "center",
marginTop: 20,
}}
>
<TouchableOpacity onPress={handleSignIn} style={styles.button}>
<Text style={styles.buttonText}>Login as User</Text>
</TouchableOpacity>
</View>
<View
style={{
flex: 1,
flexDirection: "row",
justifyContent: "center",
alignItems: "center",
marginTop: 20,
}}
>
<TouchableOpacity
onPress={() => navigator.replace("AdminLogin")}
style={styles.button}
>
<Text style={styles.buttonText}>Login As Admin</Text>
</TouchableOpacity>
</View>
</View>
<Text style={{ color: "white", bottom: 160, position: "absolute" }}>
Copyright ©Bombay Rotary Club
</Text>
</ScrollView>
);
};
export default LoginScreen;
const styles = StyleSheet.create({
container: {
// flex: 1,
justifyContent: "center",
alignItems: "center",
// position: "relative",
backgroundColor: "#0782F9",
paddingBottom: 190,
paddingTop: 40,
},
inputContainer: {
width: "80%",
},
input: {
backgroundColor: "white",
paddingHorizontal: 15,
paddingVertical: 10,
borderRadius: 30,
marginTop: 25,
borderWidth: 2,
borderColor: "#FFA500",
},
buttonContainer: {
width: "100%",
justifyContent: "center",
alignItems: "center",
marginVertical: 40,
},
button: {
backgroundColor: "#FFA500",
width: "60%",
height: 60,
padding: 15,
borderRadius: 40,
alignItems: "center",
justifyContent: "center",
marginBottom: 20,
marginLeft: 15,
},
buttonOutline: {
backgroundColor: "white",
marginTop: 5,
borderColor: "#FFA500",
borderWidth: 2,
},
buttonText: {
color: "white",
fontWeight: "700",
fontSize: 16,
},
buttonOutlineText: {
color: "#FFA500",
fontWeight: "700",
fontSize: 16,
},
button1: {
backgroundColor: "#0782F9",
width: "60%",
height: 60,
padding: 15,
borderRadius: 40,
alignItems: "center",
justifyContent: "center",
marginTop: 20,
marginLeft: 15,
},
buttonOutline1: {
backgroundColor: "#F79AC0",
marginTop: 5,
},
buttonOutlineText1: {
color: "white",
fontWeight: "700",
fontSize: 16,
},
});