@@ -5,8 +5,10 @@ import { Button } from '../components/ui/Button';
55import { Input } from '../components/ui/Input' ;
66import { Checkbox } from '../components/ui/Checkbox' ;
77import { router } from 'expo-router' ;
8+ import { useUser } from '@/contexts/UserContext' ;
89
910export default function LoginScreen ( ) {
11+ const { setName : setUserName } = useUser ( ) ;
1012 const [ email , setEmail ] = useState ( '' ) ;
1113 const [ password , setPassword ] = useState ( '' ) ;
1214 const [ rememberMe , setRememberMe ] = useState ( false ) ;
@@ -21,33 +23,28 @@ export default function LoginScreen() {
2123 const handleLogin = async ( ) => {
2224 setErrors ( { } ) ;
2325
24- // Simple validation
2526 const newErrors : { email ?: string ; password ?: string } = { } ;
26-
27- if ( ! email ) {
28- newErrors . email = 'Email is required' ;
29- } else if ( ! / \S + @ \S + \. \S + / . test ( email ) ) {
30- newErrors . email = 'Please enter a valid email' ;
31- }
32-
33- if ( ! password ) {
34- newErrors . password = 'Password is required' ;
35- } else if ( password . length < 6 ) {
36- newErrors . password = 'Password must be at least 6 characters' ;
37- }
38-
27+
28+ if ( ! email ) newErrors . email = 'Email is required' ;
29+ else if ( ! / \S + @ \S + \. \S + / . test ( email ) ) newErrors . email = 'Please enter a valid email' ;
30+
31+ if ( ! password ) newErrors . password = 'Password is required' ;
32+ else if ( password . length < 6 ) newErrors . password = 'Password must be at least 6 characters' ;
33+
3934 if ( Object . keys ( newErrors ) . length > 0 ) {
4035 setErrors ( newErrors ) ;
4136 return ;
4237 }
43-
38+
4439 setIsLoading ( true ) ;
45-
40+
4641 try {
4742 // Simulate API call
4843 await new Promise ( resolve => setTimeout ( resolve , 1500 ) ) ;
49-
50- // Navigate to main screen after successful login
44+
45+ // Set the name (this mimics what signup does)
46+ setUserName ( 'Returning User' ) ; // You can replace this with a real name from API later
47+
5148 router . replace ( '/home' ) ;
5249 } catch ( error ) {
5350 console . error ( 'Login error:' , error ) ;
@@ -57,7 +54,6 @@ export default function LoginScreen() {
5754 } ;
5855
5956 const handleForgotPassword = ( ) => {
60- // For now, just go back to main screen since we don't have forgot password yet
6157 router . push ( '/(tabs)' ) ;
6258 } ;
6359
0 commit comments