import { useState } from "react"; import { View, TextInput, StyleSheet, Alert, KeyboardAvoidingView, Platform, TouchableOpacity, ActivityIndicator, ScrollView, } from "react-native"; import { router } from "expo-router"; import { authClient } from "@/lib/auth/client"; import { ThemedView } from "@/components/themed-view"; import { ThemedText } from "@/components/themed-text"; export default function RegisterScreen() { const [username, setUsername] = useState(""); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [isLoading, setIsLoading] = useState(false); const handleRegister = async () => { if (!username.trim() || !email.trim() || !password.trim()) { Alert.alert("错误", "请填写所有必填字段"); return; } if (password !== confirmPassword) { Alert.alert("错误", "两次输入的密码不一致"); return; } if (password.length < 6) { Alert.alert("错误", "密码长度至少为 6 位"); return; } setIsLoading(true); try { await authClient.signUp.email({ email: email.trim(), password, name: username.trim(), }); Alert.alert("注册成功", "请登录您的账号", [ { text: "确定", onPress: () => router.replace("/(auth)/login") }, ]); } catch (error: any) { Alert.alert("注册失败", error?.message || "注册失败,请稍后重试"); } finally { setIsLoading(false); } }; return ( 创建账号 填写信息完成注册 {isLoading ? ( ) : ( 注册 )} router.back()} disabled={isLoading} > 已有账号?立即登录 ); } const styles = StyleSheet.create({ container: { flex: 1, }, scrollContent: { flexGrow: 1, }, content: { flex: 1, padding: 24, justifyContent: "center", }, title: { marginBottom: 8, textAlign: "center", }, subtitle: { marginBottom: 32, textAlign: "center", opacity: 0.7, }, form: { gap: 16, }, input: { borderWidth: 1, borderColor: "#ddd", borderRadius: 8, padding: 12, fontSize: 16, backgroundColor: "#fff", }, button: { backgroundColor: "#007AFF", padding: 16, borderRadius: 8, alignItems: "center", marginTop: 8, }, buttonDisabled: { opacity: 0.6, }, buttonText: { color: "#fff", fontSize: 16, fontWeight: "600", }, loginLink: { alignItems: "center", marginTop: 8, }, loginText: { color: "#007AFF", fontSize: 14, }, });