import { useState } from "react"; import { View, Text, StyleSheet, Alert, KeyboardAvoidingView, Platform, ScrollView, } from "react-native"; import { router } from "expo-router"; import Animated, { FadeIn, FadeInDown, FadeInUp, } from "react-native-reanimated"; import { Ionicons } from "@expo/vector-icons"; import { authClient } from "../../src/lib/authClient"; import { getAuthError } from "../../src/lib/errors"; import { GradientBackground, GlassCard, GlassButton, GlassInput } from "../../src/components/ui"; import { colors, spacing, radius, typography } from "../../src/theme"; export default function ResetPasswordScreen() { const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [isLoading, setIsLoading] = useState(false); const [isSuccess, setIsSuccess] = useState(false); const [error, setError] = useState(null); const showError = (message: string) => { setError(message); if (Platform.OS !== 'web') { Alert.alert("Error", message); } }; const clearError = () => setError(null); const handleResetPassword = async () => { clearError(); // Validate password if (!password) { showError("Please enter a new password"); return; } if (password.length < 8) { showError("Password must be at least 8 characters"); return; } if (password !== confirmPassword) { showError("Passwords do not match"); return; } setIsLoading(true); const { error: updateError } = await authClient.auth.updateUser({ password, }); setIsLoading(false); if (updateError) { showError(getAuthError(updateError)); } else { setIsSuccess(true); } }; const handleContinue = () => { // Navigate to main app router.replace("/"); }; // Success screen if (isSuccess) { return ( Password Updated Your password has been successfully reset. You can now use your new password to sign in. Continue to App ); } return ( {/* Header */} Create New Password Enter your new password below {/* Form Card */} {/* Error Message */} {error && ( {error} )} {/* Form Fields */} { clearError(); setPassword(text); }} secureTextEntry autoCapitalize="none" autoFocus icon={} /> { clearError(); setConfirmPassword(text); }} secureTextEntry autoCapitalize="none" icon={} /> Password must be at least 8 characters Reset Password {/* Back to Login Link */} router.replace("/(auth)/login")} > Back to login ); } const styles = StyleSheet.create({ container: { flex: 1, }, centeredContainer: { flex: 1, justifyContent: "center", alignItems: "center", }, centeredContent: { alignItems: "center", paddingHorizontal: spacing.lg, }, scrollContent: { flexGrow: 1, }, content: { flex: 1, paddingHorizontal: spacing.lg, paddingTop: 80, paddingBottom: spacing.xl, }, headerContainer: { alignItems: "center", marginBottom: spacing.xl, }, logoContainer: { width: 80, height: 80, borderRadius: 40, backgroundColor: colors.primaryLight, justifyContent: "center", alignItems: "center", marginBottom: spacing.md, }, successIconContainer: { width: 100, height: 100, borderRadius: 50, backgroundColor: colors.successLight, justifyContent: "center", alignItems: "center", marginBottom: spacing.lg, }, title: { ...typography.largeTitle, color: colors.text, marginBottom: spacing.xs, textAlign: "center", }, subtitle: { ...typography.body, color: colors.textSecondary, textAlign: "center", }, formContainer: { marginBottom: spacing.lg, }, errorContainer: { flexDirection: "row", alignItems: "center", backgroundColor: colors.errorLight, padding: spacing.md, borderRadius: radius.md, marginBottom: spacing.md, gap: spacing.sm, }, errorText: { ...typography.subhead, color: colors.error, flex: 1, }, form: { gap: spacing.sm, }, passwordHint: { ...typography.caption1, color: colors.textTertiary, textAlign: "center", marginTop: spacing.xs, }, footerContainer: { alignItems: "center", }, });