-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUserRegistration.tsx
159 lines (152 loc) · 4.9 KB
/
UserRegistration.tsx
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
import React, { FC, ReactElement, useState } from "react";
import {
Image,
ScrollView,
Text,
TextInput,
TouchableOpacity,
View,
} from "react-native";
import { useNavigation } from "@react-navigation/native";
import Styles from "./Styles";
import { useAuth } from "./context/AuthContext";
import { appleAuth } from "@invertase/react-native-apple-authentication";
export const UserRegistration: FC<{}> = ({}): ReactElement => {
const { signUp, logInWithGoogle, logInWithApple } = useAuth();
const navigation = useNavigation();
const [email, setEmail] = useState("");
const [firstName, setFirstName] = useState("");
const [lastName, setLastName] = useState("");
const [password, setPassword] = useState("");
const [loading, setLoading] = useState(false);
const signUpWithEmail = async () => {
try {
setLoading(true);
if (
firstName === "" ||
lastName === "" ||
email === "" ||
password === ""
) {
alert("Please fill out all boxes before registering");
return;
}
await signUp(firstName, lastName, email, password);
alert(
"Please verify your email address by clicking the link that is sent to your email!"
);
} catch (error: any) {
switch (error.code) {
case "auth/email-already-in-use":
alert(
"This email is already registered with us. Please login using that email."
);
break;
default:
alert("There was an error processing your request");
}
}
setLoading(false);
};
const googleLogin = async () => {
try {
setLoading(true);
await logInWithGoogle();
} catch (error: any) {
alert(error);
}
setLoading(false);
};
const appleLogin = async () => {
try {
setLoading(true);
await logInWithApple();
} catch (error: any) {
alert(error);
}
setLoading(false);
};
return (
<ScrollView>
{!loading ? (
<View style={Styles.login_wrapper}>
<View style={Styles.form}>
<TextInput
style={Styles.form_input}
value={email}
placeholder={"Email"}
onChangeText={(text) => setEmail(text)}
autoCapitalize={"none"}
keyboardType={"email-address"}
/>
<TextInput
style={Styles.form_input}
value={firstName}
placeholder={"First Name"}
onChangeText={(text) => setFirstName(text)}
autoCapitalize={"none"}
keyboardType={"email-address"}
/>
<TextInput
style={Styles.form_input}
value={lastName}
placeholder={"Last Name"}
onChangeText={(text) => setLastName(text)}
autoCapitalize={"none"}
keyboardType={"email-address"}
/>
<TextInput
style={Styles.form_input}
value={password}
placeholder={"Password"}
secureTextEntry
onChangeText={(text) => setPassword(text)}
/>
<TouchableOpacity onPress={signUpWithEmail}>
<View style={Styles.button}>
<Text style={Styles.button_label}>{"Sign Up"}</Text>
</View>
</TouchableOpacity>
</View>
<View style={Styles.login_social}>
<View style={Styles.login_social_separator}>
<View style={Styles.login_social_separator_line} />
<Text style={Styles.login_social_separator_text}>{"or"}</Text>
<View style={Styles.login_social_separator_line} />
</View>
<View style={Styles.login_social_buttons}>
<TouchableOpacity onPress={googleLogin}>
<View style={Styles.login_social_button}>
<Image
style={Styles.login_social_icon}
source={require("./assets/icon-google.png")}
/>
</View>
</TouchableOpacity>
{appleAuth.isSupported && (
<TouchableOpacity onPress={appleLogin}>
<View style={Styles.login_social_button}>
<Image
style={Styles.login_social_icon}
source={require("./assets/icon-apple.png")}
/>
</View>
</TouchableOpacity>
)}
</View>
</View>
<>
<TouchableOpacity
onPress={() => navigation.navigate("Login" as never)}
>
<Text style={Styles.login_footer_text}>
{"Already have an account? "}
<Text style={Styles.login_footer_link}>{"Log In"}</Text>
</Text>
</TouchableOpacity>
</>
</View>
) : null}
</ScrollView>
);
};