-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignUpScreen.js
More file actions
47 lines (40 loc) · 1.48 KB
/
SignUpScreen.js
File metadata and controls
47 lines (40 loc) · 1.48 KB
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
import React, { useState } from 'react';
import { View, TextInput, Button, Alert } from 'react-native';
import { auth, firestore } from './firebase';
const SignUpScreen = ({ navigation }) => {
const [firstName, setFirstName] = useState('');
const [lastName, setLastName] = useState('');
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const handleSignUp = async () => {
try {
const userCredential = await auth.createUserWithEmailAndPassword(email, password);
// Add user information to Firestore
await firestore.collection('users').doc(userCredential.user.uid).set({
firstName,
lastName,
email,
});
// Send verification email
await userCredential.user.sendEmailVerification();
Alert.alert('Success', 'Account created successfully. Please verify your email.');
navigation.navigate('Login');
} catch (error) {
Alert.alert('Error', error.message);
}
};
return (
<View>
<TextInput placeholder="First Name" onChangeText={(text) => setFirstName(text)} />
<TextInput placeholder="Last Name" onChangeText={(text) => setLastName(text)} />
<TextInput placeholder="Email" onChangeText={(text) => setEmail(text)} />
<TextInput
placeholder="Password"
secureTextEntry
onChangeText={(text) => setPassword(text)}
/>
<Button title="Register" onPress={handleSignUp} />
</View>
);
};
export default SignUpScreen;