import { useState } from 'react'; import { View, Text, TextInput, Pressable, StyleSheet, ActivityIndicator, ScrollView, } from 'react-native'; import { useRouter } from 'expo-router'; import { useAuthStore } from '@/store/auth'; import { authClient } from '@/lib/auth-client'; /** * Sign up screen * Creates new account with email and password */ export default function SignUpScreen() { const router = useRouter(); const { setUser } = useAuthStore(); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [name, setName] = useState(''); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(''); const handleSignUp = async () => { setError(''); if (!email || !password || !confirmPassword || !name) { setError('All fields are required'); return; } if (password !== confirmPassword) { setError('Passwords do not match'); return; } if (password.length < 6) { setError('Password must be at least 6 characters'); return; } try { setIsLoading(true); const session = await authClient.signUp.email({ email, password, name, }); const sessionData = (session as any)?.data; if (sessionData && (sessionData.user || sessionData.data?.user)) { const user = sessionData.user || sessionData.data?.user; setUser(user); // Go to passkey prompt (optional, skippable) router.replace('/(auth)/passkey-prompt'); } } catch (err) { const message = err instanceof Error ? err.message : 'Sign up failed'; setError(message); console.error('Sign up error:', err); } finally { setIsLoading(false); } }; return ( Create Account Join Bagsy today {error && {error}} {isLoading ? ( ) : ( Create Account )} router.back()} disabled={isLoading}> Already have an account? Sign In ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', }, content: { padding: 20, paddingVertical: 40, }, title: { fontSize: 28, fontWeight: 'bold', marginBottom: 8, }, subtitle: { fontSize: 16, color: '#666', marginBottom: 24, }, input: { borderWidth: 1, borderColor: '#ddd', borderRadius: 8, padding: 12, marginBottom: 12, fontSize: 16, }, button: { paddingVertical: 12, paddingHorizontal: 24, borderRadius: 8, alignItems: 'center', justifyContent: 'center', marginVertical: 8, }, primaryButton: { backgroundColor: '#007AFF', }, buttonText: { color: '#fff', fontSize: 16, fontWeight: '600', }, textButton: { paddingVertical: 12, alignItems: 'center', }, textButtonText: { color: '#007AFF', fontSize: 14, }, divider: { height: 1, backgroundColor: '#eee', marginVertical: 24, }, error: { color: '#ff3333', fontSize: 14, marginBottom: 12, textAlign: 'center', padding: 12, backgroundColor: '#ffe5e5', borderRadius: 6, }, });