import { useRouter } from "expo-router"; import { useState } from "react"; import { ActivityIndicator, Pressable, StyleSheet, Text, TextInput, View, } from "react-native"; import { login, register } from "../../src/api/auth"; import { validateHandle } from "../../src/utils/handleValidation"; export default function LoginScreen() { const router = useRouter(); const [mode, setMode] = useState<"login" | "register">("login"); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [handle, setHandle] = useState(""); const [displayName, setDisplayName] = useState(""); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); const submit = async () => { setError(null); if (mode === "register") { const handleErr = validateHandle(handle); if (handleErr) { setError(`Handle invalid: ${handleErr.replace(/_/g, " ")}`); return; } } setBusy(true); try { if (mode === "register") { await register({ email, password, handle, displayName }); } else { await login(email, password); } router.replace("/(tabs)/cards"); } catch { setError(mode === "login" ? "Invalid email or password" : "Could not create account"); } finally { setBusy(false); } }; return ( CardClaws The other side of you. {mode === "register" && ( <> )} {error && {error}} {busy ? ( ) : ( {mode === "login" ? "Sign in" : "Create account"} )} setMode(mode === "login" ? "register" : "login")}> {mode === "login" ? "Need an account? Register" : "Have an account? Sign in"} ); } function Field(props: React.ComponentProps) { return ( ); } const styles = StyleSheet.create({ root: { flex: 1, justifyContent: "center", padding: 24, gap: 12, backgroundColor: "#0a0a0c" }, title: { color: "#f5f5f7", fontSize: 40, fontWeight: "800", letterSpacing: -1 }, tagline: { color: "#9a9aa0", marginBottom: 24 }, input: { backgroundColor: "#1a1a1f", color: "#f5f5f7", borderRadius: 12, paddingHorizontal: 16, paddingVertical: 14, fontSize: 16, }, error: { color: "#ff453a" }, primary: { backgroundColor: "#ff3b30", borderRadius: 14, paddingVertical: 16, alignItems: "center", marginTop: 8, }, primaryText: { color: "#fff", fontWeight: "700", fontSize: 17 }, switch: { color: "#9a9aa0", textAlign: "center", marginTop: 16 }, });