import { useState } from "react"; import { View, Text, KeyboardAvoidingView, Platform, ScrollView, Alert, } from "react-native"; import { useRouter } from "expo-router"; import { useMutation, useAction } from "convex/react"; import { api } from "../../convex/_generated/api"; import { Input } from "../../components/ui/input"; import { Button } from "../../components/ui/button"; import { useTheme } from "../../components/theme"; import { useAuth } from "../_layout"; export default function LoginScreen() { const theme = useTheme(); const router = useRouter(); const { login } = useAuth(); const loginMutation = useMutation(api.auth.login); const hashPassword = useAction(api.auth.hashPassword); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [loading, setLoading] = useState(false); async function handleLogin() { if (!email || !password) { Alert.alert("Грешка", "Пополнете ги сите полиња"); return; } setLoading(true); try { const passwordHash = await hashPassword({ password }); const result = await loginMutation({ email, passwordHash }); await login(result.token, result.user._id); router.replace("/(tabs)/(home)"); } catch (e: any) { Alert.alert("Најава неуспешна", "Погрешна е-пошта или лозинка"); } finally { setLoading(false); } } return ( МојМајстор Најдете мајстор во вашата близина Немате профил? router.push("/(auth)/register")} > Регистрирајте се ); }