@rapid-rn/plugin-auth 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +188 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +147 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -0
- package/templates/AuthGuard.tsx.hbs +110 -0
- package/templates/AuthHeader.tsx.hbs +91 -0
- package/templates/ForgotPasswordScreen.tsx.hbs +204 -0
- package/templates/LoginScreen.tsx.hbs +227 -0
- package/templates/OTPScreen.tsx.hbs +288 -0
- package/templates/SignupScreen.tsx.hbs +272 -0
- package/templates/auth.service.ts.hbs +158 -0
- package/templates/auth.store.ts.hbs +117 -0
- package/templates/index.ts.hbs +7 -0
- package/templates/useAuth.ts.hbs +137 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import {
|
|
3
|
+
StyleSheet,
|
|
4
|
+
Text,
|
|
5
|
+
View,
|
|
6
|
+
KeyboardAvoidingView,
|
|
7
|
+
Platform,
|
|
8
|
+
ScrollView,
|
|
9
|
+
TouchableOpacity,
|
|
10
|
+
TextInput,
|
|
11
|
+
} from "react-native";
|
|
12
|
+
import { useRouter, useLocalSearchParams } from "expo-router";
|
|
13
|
+
import { useAuth } from "../hooks/useAuth";
|
|
14
|
+
import { AuthHeader } from "../components/AuthHeader";
|
|
15
|
+
{{#if hasTheme}}
|
|
16
|
+
import { useTheme } from "@theme";
|
|
17
|
+
{{/if}}
|
|
18
|
+
{{#if hasSharedComponents}}
|
|
19
|
+
import { Input, Button } from "@shared/components/ui";
|
|
20
|
+
{{/if}}
|
|
21
|
+
|
|
22
|
+
export const OTPScreen = () => {
|
|
23
|
+
const { email } = useLocalSearchParams<{ email: string }>();
|
|
24
|
+
const [otp, setOtp] = useState("");
|
|
25
|
+
const [newPassword, setNewPassword] = useState("");
|
|
26
|
+
const [confirmPassword, setConfirmPassword] = useState("");
|
|
27
|
+
const [resetToken, setResetToken] = useState<string | null>(null);
|
|
28
|
+
const [validationError, setValidationError] = useState<string | null>(null);
|
|
29
|
+
const { verifyOTP, resetPassword, loading, error, clearError } = useAuth();
|
|
30
|
+
const router = useRouter();
|
|
31
|
+
{{#if hasTheme}}
|
|
32
|
+
const { colors, typography } = useTheme();
|
|
33
|
+
{{/if}}
|
|
34
|
+
|
|
35
|
+
const bgColor = {{#if hasTheme}}colors.background{{else}}"#fff"{{/if}};
|
|
36
|
+
const textColor = {{#if hasTheme}}colors.text{{else}}"#111"{{/if}};
|
|
37
|
+
const mutedColor = {{#if hasTheme}}colors.muted{{else}}"#666"{{/if}};
|
|
38
|
+
const errorColor = {{#if hasTheme}}colors.notification{{else}}"#e53935"{{/if}};
|
|
39
|
+
const primaryColor = {{#if hasTheme}}colors.primary{{else}}"#6C63FF"{{/if}};
|
|
40
|
+
const titleSize = {{#if hasTheme}}typography.sizes.xxl{{else}}32{{/if}};
|
|
41
|
+
const bodySize = {{#if hasTheme}}typography.sizes.md{{else}}16{{/if}};
|
|
42
|
+
const smallSize = {{#if hasTheme}}typography.sizes.sm{{else}}14{{/if}};
|
|
43
|
+
const boldFont = {{#if hasTheme}}typography.fonts.bold{{else}}undefined{{/if}};
|
|
44
|
+
|
|
45
|
+
// Step 1: Verify OTP
|
|
46
|
+
const handleVerifyOTP = async () => {
|
|
47
|
+
if (otp.length < 6) {
|
|
48
|
+
setValidationError("Please enter the 6-digit code.");
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
clearError();
|
|
52
|
+
setValidationError(null);
|
|
53
|
+
const result = await verifyOTP(email ?? "", otp);
|
|
54
|
+
if (result) {
|
|
55
|
+
setResetToken(result.resetToken);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// Step 2: Reset password (after OTP verified)
|
|
60
|
+
const handleResetPassword = async () => {
|
|
61
|
+
setValidationError(null);
|
|
62
|
+
if (!newPassword || !confirmPassword) {
|
|
63
|
+
setValidationError("Please fill in both password fields.");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (newPassword !== confirmPassword) {
|
|
67
|
+
setValidationError("Passwords do not match.");
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (newPassword.length < 8) {
|
|
71
|
+
setValidationError("Password must be at least 8 characters.");
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
clearError();
|
|
75
|
+
const success = await resetPassword(resetToken ?? "", newPassword);
|
|
76
|
+
if (success) {
|
|
77
|
+
router.replace("/(auth)/login");
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const displayError = validationError ?? error;
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<KeyboardAvoidingView
|
|
85
|
+
behavior={Platform.OS === "ios" ? "padding" : "height"}
|
|
86
|
+
style={[styles.container, { backgroundColor: bgColor }]}
|
|
87
|
+
>
|
|
88
|
+
{/* Custom Auth Header */}
|
|
89
|
+
<AuthHeader title={resetToken ? "Reset Password" : "OTP Verification"} showBackButton={true} />
|
|
90
|
+
|
|
91
|
+
<ScrollView contentContainerStyle={styles.scrollContainer} keyboardShouldPersistTaps="handled">
|
|
92
|
+
{/* Header */}
|
|
93
|
+
<View style={styles.header}>
|
|
94
|
+
<Text style={[styles.title, { color: textColor, fontSize: titleSize, fontFamily: boldFont }]}>
|
|
95
|
+
{resetToken ? "New Password 🔒" : "Enter Code 📨"}
|
|
96
|
+
</Text>
|
|
97
|
+
<Text style={[styles.subtitle, { color: mutedColor, fontSize: bodySize }]}>
|
|
98
|
+
{resetToken
|
|
99
|
+
? "Choose a strong new password for your account"
|
|
100
|
+
: `We sent a 6-digit code to ${email ?? "your email"}.\nHint: use 123456 in demo mode`}
|
|
101
|
+
</Text>
|
|
102
|
+
</View>
|
|
103
|
+
|
|
104
|
+
<View style={styles.form}>
|
|
105
|
+
{!resetToken ? (
|
|
106
|
+
/* ── Step 1: OTP entry ─────────────────────────────────────────── */
|
|
107
|
+
<>
|
|
108
|
+
{{#if hasSharedComponents}}
|
|
109
|
+
<Input
|
|
110
|
+
label="Verification Code"
|
|
111
|
+
placeholder="123456"
|
|
112
|
+
value={otp}
|
|
113
|
+
onChangeText={(t) => { clearError(); setValidationError(null); setOtp(t.replace(/\D/g, "")); }}
|
|
114
|
+
keyboardType="number-pad"
|
|
115
|
+
maxLength={6}
|
|
116
|
+
autoFocus
|
|
117
|
+
/>
|
|
118
|
+
{{else}}
|
|
119
|
+
<View style={styles.fallbackInputContainer}>
|
|
120
|
+
<Text style={[styles.fallbackLabel, { color: textColor }]}>Verification Code</Text>
|
|
121
|
+
<TextInput
|
|
122
|
+
style={[styles.fallbackInput, { color: textColor, borderColor: mutedColor }]}
|
|
123
|
+
placeholder="123456"
|
|
124
|
+
placeholderTextColor="#aaa"
|
|
125
|
+
value={otp}
|
|
126
|
+
onChangeText={(t) => { clearError(); setValidationError(null); setOtp(t.replace(/\D/g, "")); }}
|
|
127
|
+
keyboardType="number-pad"
|
|
128
|
+
maxLength={6}
|
|
129
|
+
autoFocus
|
|
130
|
+
/>
|
|
131
|
+
</View>
|
|
132
|
+
{{/if}}
|
|
133
|
+
|
|
134
|
+
{displayError ? (
|
|
135
|
+
<Text style={[styles.errorText, { color: errorColor, fontSize: smallSize }]}>
|
|
136
|
+
{displayError}
|
|
137
|
+
</Text>
|
|
138
|
+
) : null}
|
|
139
|
+
|
|
140
|
+
{{#if hasSharedComponents}}
|
|
141
|
+
<Button
|
|
142
|
+
title="Verify Code"
|
|
143
|
+
onPress={handleVerifyOTP}
|
|
144
|
+
loading={loading}
|
|
145
|
+
disabled={otp.length < 6 || loading}
|
|
146
|
+
/>
|
|
147
|
+
{{else}}
|
|
148
|
+
<TouchableOpacity
|
|
149
|
+
style={[
|
|
150
|
+
styles.fallbackButton,
|
|
151
|
+
{ backgroundColor: primaryColor },
|
|
152
|
+
(otp.length < 6 || loading) && { opacity: 0.6 }
|
|
153
|
+
]}
|
|
154
|
+
onPress={handleVerifyOTP}
|
|
155
|
+
disabled={otp.length < 6 || loading}
|
|
156
|
+
>
|
|
157
|
+
<Text style={styles.fallbackButtonText}>
|
|
158
|
+
{loading ? "Verifying..." : "Verify Code"}
|
|
159
|
+
</Text>
|
|
160
|
+
</TouchableOpacity>
|
|
161
|
+
{{/if}}
|
|
162
|
+
</>
|
|
163
|
+
) : (
|
|
164
|
+
/* ── Step 2: New password ──────────────────────────────────────── */
|
|
165
|
+
<>
|
|
166
|
+
{{#if hasSharedComponents}}
|
|
167
|
+
<Input
|
|
168
|
+
label="New Password"
|
|
169
|
+
placeholder="Min. 8 characters"
|
|
170
|
+
value={newPassword}
|
|
171
|
+
onChangeText={(t) => { clearError(); setValidationError(null); setNewPassword(t); }}
|
|
172
|
+
secureTextEntry
|
|
173
|
+
autoCapitalize="none"
|
|
174
|
+
/>
|
|
175
|
+
<Input
|
|
176
|
+
label="Confirm New Password"
|
|
177
|
+
placeholder="Re-enter new password"
|
|
178
|
+
value={confirmPassword}
|
|
179
|
+
onChangeText={(t) => { clearError(); setValidationError(null); setConfirmPassword(t); }}
|
|
180
|
+
secureTextEntry
|
|
181
|
+
autoCapitalize="none"
|
|
182
|
+
/>
|
|
183
|
+
{{else}}
|
|
184
|
+
<View style={styles.fallbackInputContainer}>
|
|
185
|
+
<Text style={[styles.fallbackLabel, { color: textColor }]}>New Password</Text>
|
|
186
|
+
<TextInput
|
|
187
|
+
style={[styles.fallbackInput, { color: textColor, borderColor: mutedColor }]}
|
|
188
|
+
placeholder="Min. 8 characters"
|
|
189
|
+
placeholderTextColor="#aaa"
|
|
190
|
+
value={newPassword}
|
|
191
|
+
onChangeText={(t) => { clearError(); setValidationError(null); setNewPassword(t); }}
|
|
192
|
+
secureTextEntry
|
|
193
|
+
autoCapitalize="none"
|
|
194
|
+
/>
|
|
195
|
+
</View>
|
|
196
|
+
<View style={styles.fallbackInputContainer}>
|
|
197
|
+
<Text style={[styles.fallbackLabel, { color: textColor }]}>Confirm New Password</Text>
|
|
198
|
+
<TextInput
|
|
199
|
+
style={[styles.fallbackInput, { color: textColor, borderColor: mutedColor }]}
|
|
200
|
+
placeholder="Re-enter new password"
|
|
201
|
+
placeholderTextColor="#aaa"
|
|
202
|
+
value={confirmPassword}
|
|
203
|
+
onChangeText={(t) => { clearError(); setValidationError(null); setConfirmPassword(t); }}
|
|
204
|
+
secureTextEntry
|
|
205
|
+
autoCapitalize="none"
|
|
206
|
+
/>
|
|
207
|
+
</View>
|
|
208
|
+
{{/if}}
|
|
209
|
+
|
|
210
|
+
{displayError ? (
|
|
211
|
+
<Text style={[styles.errorText, { color: errorColor, fontSize: smallSize }]}>
|
|
212
|
+
{displayError}
|
|
213
|
+
</Text>
|
|
214
|
+
) : null}
|
|
215
|
+
|
|
216
|
+
{{#if hasSharedComponents}}
|
|
217
|
+
<Button
|
|
218
|
+
title="Reset Password"
|
|
219
|
+
onPress={handleResetPassword}
|
|
220
|
+
loading={loading}
|
|
221
|
+
disabled={!newPassword || !confirmPassword || loading}
|
|
222
|
+
/>
|
|
223
|
+
{{else}}
|
|
224
|
+
<TouchableOpacity
|
|
225
|
+
style={[
|
|
226
|
+
styles.fallbackButton,
|
|
227
|
+
{ backgroundColor: primaryColor },
|
|
228
|
+
(!newPassword || !confirmPassword || loading) && { opacity: 0.6 }
|
|
229
|
+
]}
|
|
230
|
+
onPress={handleResetPassword}
|
|
231
|
+
disabled={!newPassword || !confirmPassword || loading}
|
|
232
|
+
>
|
|
233
|
+
<Text style={styles.fallbackButtonText}>
|
|
234
|
+
{loading ? "Resetting..." : "Reset Password"}
|
|
235
|
+
</Text>
|
|
236
|
+
</TouchableOpacity>
|
|
237
|
+
{{/if}}
|
|
238
|
+
</>
|
|
239
|
+
)}
|
|
240
|
+
</View>
|
|
241
|
+
</ScrollView>
|
|
242
|
+
</KeyboardAvoidingView>
|
|
243
|
+
);
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
const styles = StyleSheet.create({
|
|
247
|
+
container: { flex: 1 },
|
|
248
|
+
scrollContainer: {
|
|
249
|
+
flexGrow: 1,
|
|
250
|
+
justifyContent: "center",
|
|
251
|
+
padding: 24,
|
|
252
|
+
},
|
|
253
|
+
header: { marginBottom: 32 },
|
|
254
|
+
title: { fontWeight: "bold", marginBottom: 8 },
|
|
255
|
+
subtitle: {},
|
|
256
|
+
form: { width: "100%" },
|
|
257
|
+
errorText: { marginBottom: 12, textAlign: "center" },
|
|
258
|
+
/* Fallback components */
|
|
259
|
+
fallbackInputContainer: {
|
|
260
|
+
marginBottom: 16,
|
|
261
|
+
},
|
|
262
|
+
fallbackLabel: {
|
|
263
|
+
fontSize: 14,
|
|
264
|
+
fontWeight: "500",
|
|
265
|
+
marginBottom: 6,
|
|
266
|
+
},
|
|
267
|
+
fallbackInput: {
|
|
268
|
+
height: 48,
|
|
269
|
+
borderWidth: 1,
|
|
270
|
+
borderRadius: 8,
|
|
271
|
+
paddingHorizontal: 12,
|
|
272
|
+
fontSize: 16,
|
|
273
|
+
},
|
|
274
|
+
fallbackButton: {
|
|
275
|
+
height: 48,
|
|
276
|
+
borderRadius: 8,
|
|
277
|
+
justifyContent: "center",
|
|
278
|
+
alignItems: "center",
|
|
279
|
+
marginTop: 16,
|
|
280
|
+
},
|
|
281
|
+
fallbackButtonText: {
|
|
282
|
+
color: "#fff",
|
|
283
|
+
fontSize: 16,
|
|
284
|
+
fontWeight: "600",
|
|
285
|
+
},
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
export default OTPScreen;
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import {
|
|
3
|
+
StyleSheet,
|
|
4
|
+
Text,
|
|
5
|
+
View,
|
|
6
|
+
KeyboardAvoidingView,
|
|
7
|
+
Platform,
|
|
8
|
+
ScrollView,
|
|
9
|
+
TouchableOpacity,
|
|
10
|
+
TextInput,
|
|
11
|
+
} from "react-native";
|
|
12
|
+
import { useRouter } from "expo-router";
|
|
13
|
+
import { useAuth } from "../hooks/useAuth";
|
|
14
|
+
import { AuthHeader } from "../components/AuthHeader";
|
|
15
|
+
{{#if hasTheme}}
|
|
16
|
+
import { useTheme } from "@theme";
|
|
17
|
+
{{/if}}
|
|
18
|
+
{{#if hasSharedComponents}}
|
|
19
|
+
import { Input, Button } from "@shared/components/ui";
|
|
20
|
+
{{/if}}
|
|
21
|
+
|
|
22
|
+
export const SignupScreen = () => {
|
|
23
|
+
const [name, setName] = useState("");
|
|
24
|
+
const [email, setEmail] = useState("");
|
|
25
|
+
const [password, setPassword] = useState("");
|
|
26
|
+
const [confirmPassword, setConfirmPassword] = useState("");
|
|
27
|
+
const [validationError, setValidationError] = useState<string | null>(null);
|
|
28
|
+
const { signup, loading, error, clearError } = useAuth();
|
|
29
|
+
const router = useRouter();
|
|
30
|
+
{{#if hasTheme}}
|
|
31
|
+
const { colors, typography } = useTheme();
|
|
32
|
+
{{/if}}
|
|
33
|
+
|
|
34
|
+
const bgColor = {{#if hasTheme}}colors.background{{else}}"#fff"{{/if}};
|
|
35
|
+
const textColor = {{#if hasTheme}}colors.text{{else}}"#111"{{/if}};
|
|
36
|
+
const mutedColor = {{#if hasTheme}}colors.muted{{else}}"#666"{{/if}};
|
|
37
|
+
const errorColor = {{#if hasTheme}}colors.notification{{else}}"#e53935"{{/if}};
|
|
38
|
+
const primaryColor = {{#if hasTheme}}colors.primary{{else}}"#6C63FF"{{/if}};
|
|
39
|
+
const titleSize = {{#if hasTheme}}typography.sizes.xxl{{else}}32{{/if}};
|
|
40
|
+
const bodySize = {{#if hasTheme}}typography.sizes.md{{else}}16{{/if}};
|
|
41
|
+
const smallSize = {{#if hasTheme}}typography.sizes.sm{{else}}14{{/if}};
|
|
42
|
+
const boldFont = {{#if hasTheme}}typography.fonts.bold{{else}}undefined{{/if}};
|
|
43
|
+
|
|
44
|
+
const handleSignup = async () => {
|
|
45
|
+
setValidationError(null);
|
|
46
|
+
if (!name || !email || !password || !confirmPassword) {
|
|
47
|
+
setValidationError("Please fill in all fields.");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (password !== confirmPassword) {
|
|
51
|
+
setValidationError("Passwords do not match.");
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (password.length < 8) {
|
|
55
|
+
setValidationError("Password must be at least 8 characters.");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const success = await signup({ name, email, password });
|
|
59
|
+
if (success) {
|
|
60
|
+
router.replace("/(tabs)");
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const displayError = validationError ?? error;
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<KeyboardAvoidingView
|
|
68
|
+
behavior={Platform.OS === "ios" ? "padding" : "height"}
|
|
69
|
+
style={[styles.container, { backgroundColor: bgColor }]}
|
|
70
|
+
>
|
|
71
|
+
{/* Custom Auth Header */}
|
|
72
|
+
<AuthHeader title="Sign Up" showBackButton={true} />
|
|
73
|
+
|
|
74
|
+
<ScrollView contentContainerStyle={styles.scrollContainer} keyboardShouldPersistTaps="handled">
|
|
75
|
+
{/* Header */}
|
|
76
|
+
<View style={styles.header}>
|
|
77
|
+
<Text style={[styles.title, { color: textColor, fontSize: titleSize, fontFamily: boldFont }]}>
|
|
78
|
+
Create Account 🚀
|
|
79
|
+
</Text>
|
|
80
|
+
<Text style={[styles.subtitle, { color: mutedColor, fontSize: bodySize }]}>
|
|
81
|
+
Sign up to get started with your new account
|
|
82
|
+
</Text>
|
|
83
|
+
</View>
|
|
84
|
+
|
|
85
|
+
{/* Form */}
|
|
86
|
+
<View style={styles.form}>
|
|
87
|
+
{{#if hasSharedComponents}}
|
|
88
|
+
<Input
|
|
89
|
+
label="Full Name"
|
|
90
|
+
placeholder="John Doe"
|
|
91
|
+
value={name}
|
|
92
|
+
onChangeText={(t) => { clearError(); setValidationError(null); setName(t); }}
|
|
93
|
+
autoCapitalize="words"
|
|
94
|
+
autoComplete="name"
|
|
95
|
+
/>
|
|
96
|
+
<Input
|
|
97
|
+
label="Email Address"
|
|
98
|
+
placeholder="you@example.com"
|
|
99
|
+
value={email}
|
|
100
|
+
onChangeText={(t) => { clearError(); setValidationError(null); setEmail(t); }}
|
|
101
|
+
keyboardType="email-address"
|
|
102
|
+
autoCapitalize="none"
|
|
103
|
+
autoComplete="email"
|
|
104
|
+
/>
|
|
105
|
+
<Input
|
|
106
|
+
label="Password"
|
|
107
|
+
placeholder="Min. 8 characters"
|
|
108
|
+
value={password}
|
|
109
|
+
onChangeText={(t) => { clearError(); setValidationError(null); setPassword(t); }}
|
|
110
|
+
secureTextEntry
|
|
111
|
+
autoCapitalize="none"
|
|
112
|
+
/>
|
|
113
|
+
<Input
|
|
114
|
+
label="Confirm Password"
|
|
115
|
+
placeholder="Re-enter your password"
|
|
116
|
+
value={confirmPassword}
|
|
117
|
+
onChangeText={(t) => { clearError(); setValidationError(null); setConfirmPassword(t); }}
|
|
118
|
+
secureTextEntry
|
|
119
|
+
autoCapitalize="none"
|
|
120
|
+
/>
|
|
121
|
+
{{else}}
|
|
122
|
+
{/* Fallback inputs */}
|
|
123
|
+
<View style={styles.fallbackInputContainer}>
|
|
124
|
+
<Text style={[styles.fallbackLabel, { color: textColor }]}>Full Name</Text>
|
|
125
|
+
<TextInput
|
|
126
|
+
style={[styles.fallbackInput, { color: textColor, borderColor: mutedColor }]}
|
|
127
|
+
placeholder="John Doe"
|
|
128
|
+
placeholderTextColor="#aaa"
|
|
129
|
+
value={name}
|
|
130
|
+
onChangeText={(t) => { clearError(); setValidationError(null); setName(t); }}
|
|
131
|
+
autoCapitalize="words"
|
|
132
|
+
autoComplete="name"
|
|
133
|
+
/>
|
|
134
|
+
</View>
|
|
135
|
+
<View style={styles.fallbackInputContainer}>
|
|
136
|
+
<Text style={[styles.fallbackLabel, { color: textColor }]}>Email Address</Text>
|
|
137
|
+
<TextInput
|
|
138
|
+
style={[styles.fallbackInput, { color: textColor, borderColor: mutedColor }]}
|
|
139
|
+
placeholder="you@example.com"
|
|
140
|
+
placeholderTextColor="#aaa"
|
|
141
|
+
value={email}
|
|
142
|
+
onChangeText={(t) => { clearError(); setValidationError(null); setEmail(t); }}
|
|
143
|
+
keyboardType="email-address"
|
|
144
|
+
autoCapitalize="none"
|
|
145
|
+
autoComplete="email"
|
|
146
|
+
/>
|
|
147
|
+
</View>
|
|
148
|
+
<View style={styles.fallbackInputContainer}>
|
|
149
|
+
<Text style={[styles.fallbackLabel, { color: textColor }]}>Password</Text>
|
|
150
|
+
<TextInput
|
|
151
|
+
style={[styles.fallbackInput, { color: textColor, borderColor: mutedColor }]}
|
|
152
|
+
placeholder="Min. 8 characters"
|
|
153
|
+
placeholderTextColor="#aaa"
|
|
154
|
+
value={password}
|
|
155
|
+
onChangeText={(t) => { clearError(); setValidationError(null); setPassword(t); }}
|
|
156
|
+
secureTextEntry
|
|
157
|
+
autoCapitalize="none"
|
|
158
|
+
/>
|
|
159
|
+
</View>
|
|
160
|
+
<View style={styles.fallbackInputContainer}>
|
|
161
|
+
<Text style={[styles.fallbackLabel, { color: textColor }]}>Confirm Password</Text>
|
|
162
|
+
<TextInput
|
|
163
|
+
style={[styles.fallbackInput, { color: textColor, borderColor: mutedColor }]}
|
|
164
|
+
placeholder="Re-enter your password"
|
|
165
|
+
placeholderTextColor="#aaa"
|
|
166
|
+
value={confirmPassword}
|
|
167
|
+
onChangeText={(t) => { clearError(); setValidationError(null); setConfirmPassword(t); }}
|
|
168
|
+
secureTextEntry
|
|
169
|
+
autoCapitalize="none"
|
|
170
|
+
/>
|
|
171
|
+
</View>
|
|
172
|
+
{{/if}}
|
|
173
|
+
|
|
174
|
+
{/* Error message */}
|
|
175
|
+
{displayError ? (
|
|
176
|
+
<Text style={[styles.errorText, { color: errorColor, fontSize: smallSize }]}>
|
|
177
|
+
{displayError}
|
|
178
|
+
</Text>
|
|
179
|
+
) : null}
|
|
180
|
+
|
|
181
|
+
{{#if hasSharedComponents}}
|
|
182
|
+
<Button
|
|
183
|
+
title="Create Account"
|
|
184
|
+
onPress={handleSignup}
|
|
185
|
+
loading={loading}
|
|
186
|
+
disabled={!name || !email || !password || !confirmPassword || loading}
|
|
187
|
+
/>
|
|
188
|
+
{{else}}
|
|
189
|
+
{/* Fallback button */}
|
|
190
|
+
<TouchableOpacity
|
|
191
|
+
style={[
|
|
192
|
+
styles.fallbackButton,
|
|
193
|
+
{ backgroundColor: primaryColor },
|
|
194
|
+
(!name || !email || !password || !confirmPassword || loading) && { opacity: 0.6 }
|
|
195
|
+
]}
|
|
196
|
+
onPress={handleSignup}
|
|
197
|
+
disabled={!name || !email || !password || !confirmPassword || loading}
|
|
198
|
+
>
|
|
199
|
+
<Text style={styles.fallbackButtonText}>
|
|
200
|
+
{loading ? "Creating account..." : "Create Account"}
|
|
201
|
+
</Text>
|
|
202
|
+
</TouchableOpacity>
|
|
203
|
+
{{/if}}
|
|
204
|
+
</View>
|
|
205
|
+
|
|
206
|
+
{/* Login link */}
|
|
207
|
+
<View style={styles.footer}>
|
|
208
|
+
<Text style={[styles.footerText, { color: mutedColor, fontSize: bodySize }]}>
|
|
209
|
+
Already have an account?{" "}
|
|
210
|
+
</Text>
|
|
211
|
+
<TouchableOpacity onPress={() => router.push("/(auth)/login")}>
|
|
212
|
+
<Text style={[styles.link, { color: primaryColor, fontSize: bodySize, fontFamily: boldFont }]}>
|
|
213
|
+
Log in
|
|
214
|
+
</Text>
|
|
215
|
+
</TouchableOpacity>
|
|
216
|
+
</View>
|
|
217
|
+
</ScrollView>
|
|
218
|
+
</KeyboardAvoidingView>
|
|
219
|
+
);
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const styles = StyleSheet.create({
|
|
223
|
+
container: { flex: 1 },
|
|
224
|
+
scrollContainer: {
|
|
225
|
+
flexGrow: 1,
|
|
226
|
+
justifyContent: "center",
|
|
227
|
+
padding: 24,
|
|
228
|
+
},
|
|
229
|
+
header: { marginBottom: 32 },
|
|
230
|
+
title: { fontWeight: "bold", marginBottom: 8 },
|
|
231
|
+
subtitle: {},
|
|
232
|
+
form: { width: "100%", marginBottom: 24 },
|
|
233
|
+
errorText: { marginBottom: 12, textAlign: "center" },
|
|
234
|
+
link: { fontWeight: "600" },
|
|
235
|
+
footer: {
|
|
236
|
+
flexDirection: "row",
|
|
237
|
+
justifyContent: "center",
|
|
238
|
+
alignItems: "center",
|
|
239
|
+
marginTop: 8,
|
|
240
|
+
},
|
|
241
|
+
footerText: {},
|
|
242
|
+
/* Fallback components */
|
|
243
|
+
fallbackInputContainer: {
|
|
244
|
+
marginBottom: 16,
|
|
245
|
+
},
|
|
246
|
+
fallbackLabel: {
|
|
247
|
+
fontSize: 14,
|
|
248
|
+
fontWeight: "500",
|
|
249
|
+
marginBottom: 6,
|
|
250
|
+
},
|
|
251
|
+
fallbackInput: {
|
|
252
|
+
height: 48,
|
|
253
|
+
borderWidth: 1,
|
|
254
|
+
borderRadius: 8,
|
|
255
|
+
paddingHorizontal: 12,
|
|
256
|
+
fontSize: 16,
|
|
257
|
+
},
|
|
258
|
+
fallbackButton: {
|
|
259
|
+
height: 48,
|
|
260
|
+
borderRadius: 8,
|
|
261
|
+
justifyContent: "center",
|
|
262
|
+
alignItems: "center",
|
|
263
|
+
marginTop: 16,
|
|
264
|
+
},
|
|
265
|
+
fallbackButtonText: {
|
|
266
|
+
color: "#fff",
|
|
267
|
+
fontSize: 16,
|
|
268
|
+
fontWeight: "600",
|
|
269
|
+
},
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
export default SignupScreen;
|