import { useState } from 'react'; import { View, Text, TextInput, TouchableOpacity, ActivityIndicator, Alert, KeyboardAvoidingView, Platform } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; import { useLocalSearchParams, router } from 'expo-router'; import { useAuthStore } from '../../stores/authStore'; export default function LoginScreen() { const { tenantSlug } = useLocalSearchParams<{ tenantSlug: string }>(); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const { login, isLoading } = useAuthStore(); const handleLogin = async () => { if (!email.trim() || !password) return Alert.alert('Required', 'Please enter email and password.'); try { await login(tenantSlug, email.trim(), password); router.replace('/(app)/dashboard'); } catch (e: any) { const msg = e?.response?.data?.message ?? 'Login failed. Check your credentials.'; Alert.alert('Login Failed', Array.isArray(msg) ? msg.join('\n') : msg); } }; return ( router.back()} style={{ marginBottom: 32 }} hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}> ← Back Welcome back Signing in to {tenantSlug} {/* Email */} Email {/* Password */} Password setShowPassword(!showPassword)} hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}> {showPassword ? 'Hide' : 'Show'} {isLoading ? : Sign In } ); }