diff --git a/client/src/auth/SignIn.jsx b/client/src/auth/SignIn.jsx index 66506d7..41ad06a 100644 --- a/client/src/auth/SignIn.jsx +++ b/client/src/auth/SignIn.jsx @@ -4,23 +4,21 @@ export default function SignIn() { const [warningMsg, setwarningMsg] = useState(''); - const handelFormSubmit = async (e) => { - e.preventDefault() + const handleFormSubmit = async (e) => { + e.preventDefault(); setwarningMsg(''); - const form = e.target - + const form = e.target; const email = form.email.value; const password = form.password.value; - const userDetails = { email, password } + const userDetails = { email, password }; - const response = await signin(userDetails) - if (response.signin) { - window.open('/', '_parent') - console.log(response) - } - else { - setwarningMsg(response.msg) + const response = await signin(userDetails); + if (response?.signin) { + window.open('/', '_parent'); + console.log(response); + } else { + setwarningMsg(response?.msg || 'An error occurred'); } } @@ -31,111 +29,21 @@ export default function SignIn() { headers: { 'Content-type': 'application/json' }, - credentials:"include", + credentials: "include", body: JSON.stringify(userDetails) - }) - const data = await response.json() - return data + }); + return await response.json(); } catch (error) { - console.log(error) + console.log(error); + return { signin: false, msg: 'Error signing in' }; } } return ( <>
- - - - - - - - - - - - - - - - -
- - -
-
- - - {/* form */} -
+

Welcome back !

@@ -163,7 +71,7 @@ export default function SignIn() { {/* warning message */}
{warningMsg}   - {(warningMsg==="User not exists") && Sign-up} + {warningMsg?.toLowerCase() === "user not exists" && Sign-up}
@@ -183,12 +91,6 @@ export default function SignIn() {
- -
);