66
77*/
88
9- import React from ' react' ;
10- import ' ./LoginPage.css' ; // Make sure to create an appropriate CSS file for styling
9+ import React from " react" ;
10+ import " ./LoginPage.css" ; // Make sure to create an appropriate CSS file for styling
1111import { Link , useNavigate } from "react-router-dom" ;
12- import { useState } from 'react' ;
13- import useAuth from '../hooks/useAuth' ;
12+ import { useState } from "react" ;
13+ import useAuth from "../hooks/useAuth" ;
14+ import { useUser } from "../contexts/UserProvider" ;
1415
1516const LoginBox = ( ) => {
1617 const navigate = useNavigate ( ) ;
18+
19+ /*
1720 const { login } = useAuth();
1821
22+ */
23+
24+ const { auth } = useUser ( ) ;
25+
26+ console . log ( auth ) ;
27+
28+ const login = auth . login ;
29+
1930 const [ formData , setFormData ] = useState ( {
20- email : '' ,
21- password : ''
31+ email : "" ,
32+ password : "" ,
2233 } ) ;
2334
24- const [ errorMessage , setErrorMessage ] = useState ( '' ) ;
35+ const [ errorMessage , setErrorMessage ] = useState ( "" ) ;
2536 const [ showPassword , setShowPassword ] = useState ( false ) ;
2637
27-
2838 const handleChange = ( e ) => {
2939 const { name, value } = e . target ;
30- setFormData ( prevState => ( {
40+ setFormData ( ( prevState ) => ( {
3141 ...prevState ,
32- [ name ] : value
42+ [ name ] : value ,
3343 } ) ) ;
3444 } ;
3545
@@ -42,17 +52,19 @@ const LoginBox = () => {
4252 try {
4353 await login ( lowerCaseEmail , password ) ;
4454 // Redirect or perform other actions upon successful login
45- navigate ( '/' ) ;
55+ navigate ( "/" ) ;
4656 } catch ( error ) {
4757 // Error Message for Password
4858 if ( error . response && error . response . status === 401 ) {
49- setErrorMessage ( ' Incorrect password.' ) ;
50- // Error Message for Email
59+ setErrorMessage ( " Incorrect password." ) ;
60+ // Error Message for Email
5161 } else if ( error . response && error . response . status === 404 ) {
52- setErrorMessage ( 'The email you entered is not connected to an account.' ) ;
62+ setErrorMessage (
63+ "The email you entered is not connected to an account."
64+ ) ;
5365 } else {
54- // Handle other errors
55- console . error ( ' Login error:' , error ) ;
66+ // Handle other errors
67+ console . error ( " Login error:" , error ) ;
5668 }
5769 }
5870 } ;
@@ -64,12 +76,20 @@ const LoginBox = () => {
6476 return (
6577 < div className = "login-box" >
6678 < div className = "options" >
67- < Link to = "/registration" > < button className = "signup-btn" > Sign Up</ button > </ Link >
79+ < Link to = "/registration" >
80+ < button className = "signup-btn" > Sign Up</ button >
81+ </ Link >
6882 </ div >
6983 < h2 > Login</ h2 >
7084 { errorMessage && < p className = "error-message" > { errorMessage } </ p > }
7185 < form onSubmit = { handleSubmit } >
72- < input onChange = { handleChange } type = "text" name = "email" value = { formData . email } placeholder = "ScarletMail" />
86+ < input
87+ onChange = { handleChange }
88+ type = "text"
89+ name = "email"
90+ value = { formData . email }
91+ placeholder = "ScarletMail"
92+ />
7393 < div className = "password-input" >
7494 < input
7595 onChange = { handleChange }
@@ -84,7 +104,8 @@ const LoginBox = () => {
84104 className = "password-toggle"
85105 onClick = { togglePasswordVisibility }
86106 />
87- </ div > < button type = 'submit' > Sign In</ button >
107+ </ div > { " " }
108+ < button type = "submit" > Sign In</ button >
88109 </ form >
89110 </ div >
90111 ) ;
0 commit comments