-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsign-up.tsx
More file actions
96 lines (89 loc) · 2.99 KB
/
sign-up.tsx
File metadata and controls
96 lines (89 loc) · 2.99 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
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
import { useClerkErrorHandler } from "@/hooks/useClerkErrorHandler";
import { useSignUp } from "@clerk/clerk-expo";
import { Link, router } from "expo-router";
import { useState } from "react";
import {
Pressable,
TextInput,
View,
Text,
Keyboard,
TouchableWithoutFeedback,
} from "react-native";
export default function SignUp() {
const { isLoaded, signUp } = useSignUp();
const [email, setEmail] = useState<string>("");
const [password, setPassword] = useState<string>("");
const [firstName, setFirstName] = useState("");
const [lastName, setLastName] = useState("");
const [error, setError] = useState("");
const handleClerkAction = useClerkErrorHandler(setError);
const onSignUp = () =>
handleClerkAction(async () => {
if (!isLoaded) return;
await signUp.create({
emailAddress: email,
password,
firstName,
lastName,
});
await signUp.prepareEmailAddressVerification({ strategy: "email_code" });
router.push(`/verify?email=${email}`);
});
return (
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<View className="flex-1 justify-center px-6 bg-white">
<Text className="text-2xl font-bold text-primary mb-2">
Create account
</Text>
<Text className="text-sm text-shadow-strong mb-8">
Sign up to get started
</Text>
<View className="gap-y-3 mb-4">
<TextInput
value={firstName}
onChangeText={setFirstName}
placeholder="First name"
className="border border-stroke-subtle rounded-xl px-4 py-3 text-base"
/>
<TextInput
value={lastName}
onChangeText={setLastName}
placeholder="Last name"
className="border border-stroke-subtle rounded-xl px-4 py-3 text-base"
/>
<TextInput
value={email}
onChangeText={setEmail}
placeholder="Email"
keyboardType="email-address"
autoCapitalize="none"
className="border border-stroke-subtle rounded-xl px-4 py-3 text-base"
/>
<TextInput
value={password}
onChangeText={setPassword}
placeholder="Password"
secureTextEntry
autoCapitalize="none"
className="border border-stroke-subtle rounded-xl px-4 py-3 text-base"
/>
</View>
{error && <Text className="text-danger text-sm mb-4">{error}</Text>}
<Pressable
onPress={onSignUp}
className="bg-primary rounded-xl py-4 items-center mb-4 active:opacity-80"
>
<Text className="text-white font-semibold text-base">Sign Up</Text>
</Pressable>
<Link
href="/sign-in"
className="text-center text-sm text-shadow-strong"
>
Already have an account?{" "}
<Text className="text-primary font-medium">Sign in</Text>
</Link>
</View>
</TouchableWithoutFeedback>
);
}