import React, { useState } from 'react'; import { Pressable, StyleSheet, Text, View } from 'react-native'; import { useRouter } from 'expo-router'; import { api } from '@/api'; import { useT } from '@/i18n'; import { AuthShell } from '@/components/AuthShell'; import { Button, Field, TextField } from '@/components/ui'; import { colors, fontSize, spacing } from '@/theme'; /** Enforced by the backend; keep the two in step. */ const MIN_PASSWORD = 8; export default function RegisterScreen() { const router = useRouter(); const t = useT(); const [firstName, setFirstName] = useState(''); const [lastName, setLastName] = useState(''); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [showPass, setShowPass] = useState(false); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); async function onSubmit() { const mail = email.trim(); if (!mail || !mail.includes('@')) return setError(t('register.badEmail')); if (password.length < MIN_PASSWORD) return setError(t('register.shortPassword', { count: MIN_PASSWORD })); setError(null); setLoading(true); try { await api.auth.register({ email: mail, password, firstName: firstName.trim() || undefined, lastName: lastName.trim() || undefined, }); // The account exists but has no session until the code is verified. router.replace(`/verify?email=${encodeURIComponent(mail)}`); } catch (e: any) { setError(e?.fields?.email?.[0] ? t('register.emailTaken') : (e?.message ?? t('common.tryAgain'))); } finally { setLoading(false); } } return ( setShowPass((v) => !v)} style={styles.showPass} hitSlop={8}> {showPass ? t('login.hide') : t('login.show')}