diff --git a/.gitignore b/.gitignore index f8c6c2e..2a6edee 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,4 @@ app-example # generated native folders /ios /android +.git-credentials diff --git a/app/(auth)/_layout.tsx b/app/(auth)/_layout.tsx new file mode 100644 index 0000000..9ac3ffe --- /dev/null +++ b/app/(auth)/_layout.tsx @@ -0,0 +1,15 @@ +import { Stack } from 'expo-router'; +import { AppColors } from '@/constants/theme'; + +export default function AuthLayout() { + return ( + + + + ); +} diff --git a/app/(auth)/login.tsx b/app/(auth)/login.tsx new file mode 100644 index 0000000..ed77ae5 --- /dev/null +++ b/app/(auth)/login.tsx @@ -0,0 +1,210 @@ +import React, { useState, useCallback } from 'react'; +import { + View, + Text, + StyleSheet, + KeyboardAvoidingView, + Platform, + ScrollView, + TouchableOpacity, + Image, +} from 'react-native'; +import { router } from 'expo-router'; +import { useAuth } from '@/contexts/AuthContext'; +import { Button } from '@/components/ui/Button'; +import { Input } from '@/components/ui/Input'; +import { ErrorMessage } from '@/components/ui/ErrorMessage'; +import { AppColors, BorderRadius, FontSizes, Spacing } from '@/constants/theme'; + +export default function LoginScreen() { + const { login, isLoading, error, clearError } = useAuth(); + const [username, setUsername] = useState(''); + const [password, setPassword] = useState(''); + const [validationError, setValidationError] = useState(null); + + const handleLogin = useCallback(async () => { + // Clear previous errors + clearError(); + setValidationError(null); + + // Validate + if (!username.trim()) { + setValidationError('Username is required'); + return; + } + if (!password.trim()) { + setValidationError('Password is required'); + return; + } + + const success = await login({ username: username.trim(), password }); + + if (success) { + router.replace('/(tabs)'); + } + }, [username, password, login, clearError]); + + const displayError = validationError || error?.message; + + return ( + + + {/* Logo / Header */} + + + WellNuo + + Welcome Back + Sign in to continue monitoring your loved ones + + + {/* Form */} + + {displayError && ( + { + clearError(); + setValidationError(null); + }} + /> + )} + + { + setUsername(text); + setValidationError(null); + }} + autoCapitalize="none" + autoCorrect={false} + editable={!isLoading} + /> + + { + setPassword(text); + setValidationError(null); + }} + editable={!isLoading} + onSubmitEditing={handleLogin} + returnKeyType="done" + /> + + + Forgot Password? + + +