@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.
@@ -0,0 +1,204 @@
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 ForgotPasswordScreen = () => {
23
+ const [email, setEmail] = useState("");
24
+ const [successMessage, setSuccessMessage] = useState<string | null>(null);
25
+ const { forgotPassword, loading, error, clearError } = useAuth();
26
+ const router = useRouter();
27
+ {{#if hasTheme}}
28
+ const { colors, typography } = useTheme();
29
+ {{/if}}
30
+
31
+ const bgColor = {{#if hasTheme}}colors.background{{else}}"#fff"{{/if}};
32
+ const textColor = {{#if hasTheme}}colors.text{{else}}"#111"{{/if}};
33
+ const mutedColor = {{#if hasTheme}}colors.muted{{else}}"#666"{{/if}};
34
+ const errorColor = {{#if hasTheme}}colors.notification{{else}}"#e53935"{{/if}};
35
+ const successColor = {{#if hasTheme}}colors.success ?? "#2e7d32"{{else}}"#2e7d32"{{/if}};
36
+ const primaryColor = {{#if hasTheme}}colors.primary{{else}}"#6C63FF"{{/if}};
37
+ const titleSize = {{#if hasTheme}}typography.sizes.xxl{{else}}32{{/if}};
38
+ const bodySize = {{#if hasTheme}}typography.sizes.md{{else}}16{{/if}};
39
+ const smallSize = {{#if hasTheme}}typography.sizes.sm{{else}}14{{/if}};
40
+ const boldFont = {{#if hasTheme}}typography.fonts.bold{{else}}undefined{{/if}};
41
+
42
+ const handleSendCode = async () => {
43
+ if (!email) return;
44
+ clearError();
45
+ setSuccessMessage(null);
46
+ const success = await forgotPassword(email);
47
+ if (success) {
48
+ setSuccessMessage("Check your inbox — we sent a 6-digit verification code.");
49
+ // Navigate to OTP screen, passing email as a param
50
+ router.push({ pathname: "/(auth)/otp", params: { email } });
51
+ }
52
+ };
53
+
54
+ return (
55
+ <KeyboardAvoidingView
56
+ behavior={Platform.OS === "ios" ? "padding" : "height"}
57
+ style={[styles.container, { backgroundColor: bgColor }]}
58
+ >
59
+ {/* Custom Auth Header */}
60
+ <AuthHeader title="Reset Password" showBackButton={true} />
61
+
62
+ <ScrollView contentContainerStyle={styles.scrollContainer} keyboardShouldPersistTaps="handled">
63
+ {/* Header */}
64
+ <View style={styles.header}>
65
+ <Text style={[styles.title, { color: textColor, fontSize: titleSize, fontFamily: boldFont }]}>
66
+ Reset Password 🔑
67
+ </Text>
68
+ <Text style={[styles.subtitle, { color: mutedColor, fontSize: bodySize }]}>
69
+ Enter your email and we'll send you a verification code
70
+ </Text>
71
+ </View>
72
+
73
+ {/* Form */}
74
+ <View style={styles.form}>
75
+ {{#if hasSharedComponents}}
76
+ <Input
77
+ label="Email Address"
78
+ placeholder="you@example.com"
79
+ value={email}
80
+ onChangeText={(t) => { clearError(); setSuccessMessage(null); setEmail(t); }}
81
+ keyboardType="email-address"
82
+ autoCapitalize="none"
83
+ autoComplete="email"
84
+ />
85
+ {{else}}
86
+ {/* Fallback Input */}
87
+ <View style={styles.fallbackInputContainer}>
88
+ <Text style={[styles.fallbackLabel, { color: textColor }]}>Email Address</Text>
89
+ <TextInput
90
+ style={[styles.fallbackInput, { color: textColor, borderColor: mutedColor }]}
91
+ placeholder="you@example.com"
92
+ placeholderTextColor="#aaa"
93
+ value={email}
94
+ onChangeText={(t) => { clearError(); setSuccessMessage(null); setEmail(t); }}
95
+ keyboardType="email-address"
96
+ autoCapitalize="none"
97
+ autoComplete="email"
98
+ />
99
+ </View>
100
+ {{/if}}
101
+
102
+ {/* Feedback messages */}
103
+ {error ? (
104
+ <Text style={[styles.feedbackText, { color: errorColor, fontSize: smallSize }]}>
105
+ {error}
106
+ </Text>
107
+ ) : successMessage ? (
108
+ <Text style={[styles.feedbackText, { color: successColor, fontSize: smallSize }]}>
109
+ {successMessage}
110
+ </Text>
111
+ ) : null}
112
+
113
+ {{#if hasSharedComponents}}
114
+ <Button
115
+ title="Send Verification Code"
116
+ onPress={handleSendCode}
117
+ loading={loading}
118
+ disabled={!email || loading}
119
+ />
120
+ {{else}}
121
+ {/* Fallback button */}
122
+ <TouchableOpacity
123
+ style={[
124
+ styles.fallbackButton,
125
+ { backgroundColor: primaryColor },
126
+ (!email || loading) && { opacity: 0.6 }
127
+ ]}
128
+ onPress={handleSendCode}
129
+ disabled={!email || loading}
130
+ >
131
+ <Text style={styles.fallbackButtonText}>
132
+ {loading ? "Sending..." : "Send Verification Code"}
133
+ </Text>
134
+ </TouchableOpacity>
135
+ {{/if}}
136
+ </View>
137
+
138
+ {/* Back to login */}
139
+ <View style={styles.footer}>
140
+ <Text style={[styles.footerText, { color: mutedColor, fontSize: bodySize }]}>
141
+ Remembered it?{" "}
142
+ </Text>
143
+ <TouchableOpacity onPress={() => router.replace("/(auth)/login")}>
144
+ <Text style={[styles.link, { color: primaryColor, fontSize: bodySize, fontFamily: boldFont }]}>
145
+ Log in
146
+ </Text>
147
+ </TouchableOpacity>
148
+ </View>
149
+ </ScrollView>
150
+ </KeyboardAvoidingView>
151
+ );
152
+ };
153
+
154
+ const styles = StyleSheet.create({
155
+ container: { flex: 1 },
156
+ scrollContainer: {
157
+ flexGrow: 1,
158
+ justifyContent: "center",
159
+ padding: 24,
160
+ },
161
+ header: { marginBottom: 32 },
162
+ title: { fontWeight: "bold", marginBottom: 8 },
163
+ subtitle: {},
164
+ form: { width: "100%", marginBottom: 24 },
165
+ feedbackText: { marginBottom: 12, textAlign: "center" },
166
+ link: { fontWeight: "600" },
167
+ footer: {
168
+ flexDirection: "row",
169
+ justifyContent: "center",
170
+ alignItems: "center",
171
+ marginTop: 8,
172
+ },
173
+ footerText: {},
174
+ /* Fallback components */
175
+ fallbackInputContainer: {
176
+ marginBottom: 16,
177
+ },
178
+ fallbackLabel: {
179
+ fontSize: 14,
180
+ fontWeight: "500",
181
+ marginBottom: 6,
182
+ },
183
+ fallbackInput: {
184
+ height: 48,
185
+ borderWidth: 1,
186
+ borderRadius: 8,
187
+ paddingHorizontal: 12,
188
+ fontSize: 16,
189
+ },
190
+ fallbackButton: {
191
+ height: 48,
192
+ borderRadius: 8,
193
+ justifyContent: "center",
194
+ alignItems: "center",
195
+ marginTop: 16,
196
+ },
197
+ fallbackButtonText: {
198
+ color: "#fff",
199
+ fontSize: 16,
200
+ fontWeight: "600",
201
+ },
202
+ });
203
+
204
+ export default ForgotPasswordScreen;
@@ -0,0 +1,227 @@
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 LoginScreen = () => {
23
+ // Preset default login values for quick testing
24
+ const [email, setEmail] = useState("admin@example.com");
25
+ const [password, setPassword] = useState("password");
26
+ const { login, loading, error, clearError } = useAuth();
27
+ const router = useRouter();
28
+ {{#if hasTheme}}
29
+ const { colors, typography } = useTheme();
30
+ {{/if}}
31
+
32
+ const handleLogin = async () => {
33
+ if (!email || !password) return;
34
+ const success = await login({ email, password });
35
+ if (success) {
36
+ router.replace("/(tabs)");
37
+ }
38
+ };
39
+
40
+ const bgColor = {{#if hasTheme}}colors.background{{else}}"#fff"{{/if}};
41
+ const textColor = {{#if hasTheme}}colors.text{{else}}"#111"{{/if}};
42
+ const mutedColor = {{#if hasTheme}}colors.muted{{else}}"#666"{{/if}};
43
+ const errorColor = {{#if hasTheme}}colors.notification{{else}}"#e53935"{{/if}};
44
+ const primaryColor = {{#if hasTheme}}colors.primary{{else}}"#6C63FF"{{/if}};
45
+ const titleSize = {{#if hasTheme}}typography.sizes.xxl{{else}}32{{/if}};
46
+ const bodySize = {{#if hasTheme}}typography.sizes.md{{else}}16{{/if}};
47
+ const smallSize = {{#if hasTheme}}typography.sizes.sm{{else}}14{{/if}};
48
+ const boldFont = {{#if hasTheme}}typography.fonts.bold{{else}}undefined{{/if}};
49
+
50
+ return (
51
+ <KeyboardAvoidingView
52
+ behavior={Platform.OS === "ios" ? "padding" : "height"}
53
+ style={[styles.container, { backgroundColor: bgColor }]}
54
+ >
55
+ {/* Custom Auth Header — No Back Button */}
56
+ <AuthHeader title="Login" showBackButton={false} />
57
+
58
+ <ScrollView contentContainerStyle={styles.scrollContainer} keyboardShouldPersistTaps="handled">
59
+ {/* Header */}
60
+ <View style={styles.header}>
61
+ <Text style={[styles.title, { color: textColor, fontSize: titleSize, fontFamily: boldFont }]}>
62
+ Welcome Back 👋
63
+ </Text>
64
+ <Text style={[styles.subtitle, { color: mutedColor, fontSize: bodySize }]}>
65
+ Log in to continue to your account
66
+ </Text>
67
+ </View>
68
+
69
+ {/* Form */}
70
+ <View style={styles.form}>
71
+ {{#if hasSharedComponents}}
72
+ <Input
73
+ label="Email Address"
74
+ placeholder="you@example.com"
75
+ value={email}
76
+ onChangeText={(t) => { clearError(); setEmail(t); }}
77
+ keyboardType="email-address"
78
+ autoCapitalize="none"
79
+ autoComplete="email"
80
+ />
81
+ <Input
82
+ label="Password"
83
+ placeholder="••••••••"
84
+ value={password}
85
+ onChangeText={(t) => { clearError(); setPassword(t); }}
86
+ secureTextEntry
87
+ autoCapitalize="none"
88
+ />
89
+ {{else}}
90
+ {/* Fallback inputs */}
91
+ <View style={styles.fallbackInputContainer}>
92
+ <Text style={[styles.fallbackLabel, { color: textColor }]}>Email Address</Text>
93
+ <TextInput
94
+ style={[styles.fallbackInput, { color: textColor, borderColor: mutedColor }]}
95
+ placeholder="you@example.com"
96
+ placeholderTextColor="#aaa"
97
+ value={email}
98
+ onChangeText={(t) => { clearError(); setEmail(t); }}
99
+ keyboardType="email-address"
100
+ autoCapitalize="none"
101
+ autoComplete="email"
102
+ />
103
+ </View>
104
+ <View style={styles.fallbackInputContainer}>
105
+ <Text style={[styles.fallbackLabel, { color: textColor }]}>Password</Text>
106
+ <TextInput
107
+ style={[styles.fallbackInput, { color: textColor, borderColor: mutedColor }]}
108
+ placeholder="••••••••"
109
+ placeholderTextColor="#aaa"
110
+ value={password}
111
+ onChangeText={(t) => { clearError(); setPassword(t); }}
112
+ secureTextEntry
113
+ autoCapitalize="none"
114
+ />
115
+ </View>
116
+ {{/if}}
117
+
118
+ {/* Forgot password link */}
119
+ <TouchableOpacity
120
+ style={styles.forgotRow}
121
+ onPress={() => router.push("/(auth)/forgot-password")}
122
+ >
123
+ <Text style={[styles.link, { color: primaryColor, fontSize: smallSize }]}>
124
+ Forgot your password?
125
+ </Text>
126
+ </TouchableOpacity>
127
+
128
+ {/* Error message */}
129
+ {error ? (
130
+ <Text style={[styles.errorText, { color: errorColor, fontSize: smallSize }]}>
131
+ {error}
132
+ </Text>
133
+ ) : null}
134
+
135
+ {{#if hasSharedComponents}}
136
+ <Button
137
+ title="Log In"
138
+ onPress={handleLogin}
139
+ loading={loading}
140
+ disabled={!email || !password || loading}
141
+ />
142
+ {{else}}
143
+ {/* Fallback button */}
144
+ <TouchableOpacity
145
+ style={[
146
+ styles.fallbackButton,
147
+ { backgroundColor: primaryColor },
148
+ (!email || !password || loading) && { opacity: 0.6 }
149
+ ]}
150
+ onPress={handleLogin}
151
+ disabled={!email || !password || loading}
152
+ >
153
+ <Text style={styles.fallbackButtonText}>
154
+ {loading ? "Logging in..." : "Log In"}
155
+ </Text>
156
+ </TouchableOpacity>
157
+ {{/if}}
158
+ </View>
159
+
160
+ {/* Sign up link */}
161
+ <View style={styles.footer}>
162
+ <Text style={[styles.footerText, { color: mutedColor, fontSize: bodySize }]}>
163
+ Don't have an account?{" "}
164
+ </Text>
165
+ <TouchableOpacity onPress={() => router.push("/(auth)/signup")}>
166
+ <Text style={[styles.link, { color: primaryColor, fontSize: bodySize, fontFamily: boldFont }]}>
167
+ Sign up
168
+ </Text>
169
+ </TouchableOpacity>
170
+ </View>
171
+ </ScrollView>
172
+ </KeyboardAvoidingView>
173
+ );
174
+ };
175
+
176
+ const styles = StyleSheet.create({
177
+ container: { flex: 1 },
178
+ scrollContainer: {
179
+ flexGrow: 1,
180
+ justifyContent: "center",
181
+ padding: 24,
182
+ },
183
+ header: { marginBottom: 32 },
184
+ title: { fontWeight: "bold", marginBottom: 8 },
185
+ subtitle: {},
186
+ form: { width: "100%", marginBottom: 24 },
187
+ forgotRow: { alignSelf: "flex-end", marginBottom: 8 },
188
+ link: { fontWeight: "600" },
189
+ errorText: { marginBottom: 12, textAlign: "center" },
190
+ footer: {
191
+ flexDirection: "row",
192
+ justifyContent: "center",
193
+ alignItems: "center",
194
+ marginTop: 8,
195
+ },
196
+ footerText: {},
197
+ /* Fallback components */
198
+ fallbackInputContainer: {
199
+ marginBottom: 16,
200
+ },
201
+ fallbackLabel: {
202
+ fontSize: 14,
203
+ fontWeight: "500",
204
+ marginBottom: 6,
205
+ },
206
+ fallbackInput: {
207
+ height: 48,
208
+ borderWidth: 1,
209
+ borderRadius: 8,
210
+ paddingHorizontal: 12,
211
+ fontSize: 16,
212
+ },
213
+ fallbackButton: {
214
+ height: 48,
215
+ borderRadius: 8,
216
+ justifyContent: "center",
217
+ alignItems: "center",
218
+ marginTop: 16,
219
+ },
220
+ fallbackButtonText: {
221
+ color: "#fff",
222
+ fontSize: 16,
223
+ fontWeight: "600",
224
+ },
225
+ });
226
+
227
+ export default LoginScreen;