import { Link, router } from "expo-router"; import { useState } from "react"; import { KeyboardAvoidingView, Platform, Pressable, ScrollView, StyleSheet, Text, View, } from "react-native"; import { AuthBackground } from "@/components/AppBackground"; import { CollapsibleServerField } from "@/components/CollapsibleServerField"; import { HeadingText, Logo } from "@/components/Logo"; import { FullScreen } from "@/components/Screen"; import { Button } from "@/components/ui/Button"; import { Card } from "@/components/ui/Card"; import { Input } from "@/components/ui/Input"; import { fonts, spacing } from "@/constants/theme"; import { useAccounts } from "@/contexts/AccountsContext"; import { useAuthClient } from "@/contexts/AuthContext"; import { useAppTheme } from "@/contexts/ThemeContext"; export default function SignInScreen() { const authClient = useAuthClient(); const { apiUrl, registerAccount } = useAccounts(); const { colors } = useAppTheme(); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); async function handleSignIn() { setError(null); setLoading(true); const { error: signInError } = await authClient.signIn.email({ email: email.trim(), password }); if (signInError) { setLoading(false); const message = signInError.message ?? ""; if (message.toLowerCase().includes("internal") || message.includes("500")) { setError("Server error — is the API running with Postgres? Check beenvoice dev + docker."); } else { setError(message || "Invalid email or password"); } return; } const session = await authClient.getSession(); const user = session.data?.user; if (user) { await registerAccount({ instanceUrl: apiUrl, userId: user.id, email: user.email, name: user.name, }); } setLoading(false); router.replace("/(app)"); } return ( Welcome back Sign in to manage invoices on the go router.push("/(auth)/forgot-password")}> Forgot password? {error ? ( {error} ) : null}