From 34297348929e64cc2948f6b675d00674f8e3c347 Mon Sep 17 00:00:00 2001 From: Biswakalyan Bhuyan Date: Thu, 25 Jul 2024 12:44:24 +0530 Subject: added auth --- src/components/Login.js | 78 ++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/components/Login.js b/src/components/Login.js index 620ece0..1b0a9ed 100644 --- a/src/components/Login.js +++ b/src/components/Login.js @@ -2,42 +2,52 @@ import React, { useState } from 'react'; import axios from 'axios'; function Login() { - const [username, setUsername] = useState(''); - const [password, setPassword] = useState(''); - const [error, setError] = useState(''); + const [username, setUsername] = useState(''); + const [password, setPassword] = useState(''); + const [error, setError] = useState(''); - const handleSubmit = async (event) => { - event.preventDefault(); - try { - const response = await axios.post('http://localhost:5000/login', { - username, - password, - }); - console.log(response.data); - // handle successful login, e.g., redirect to admin panel - } catch (error) { - setError('Invalid credentialas'); - console.error('Error logging in', error); - } - }; + const handleSubmit = async (event) => { + event.preventDefault(); + try { + const response = await axios.post('http://localhost:5000/login', { + username, + password, + }); + console.log(response.data); + // handle successful login, e.g., redirect to admin panel + } catch (error) { + setError('Invalid credentials'); + console.error('Error logging in', error); + } + }; - return ( -
-

Login

- {error &&

{error}

} -
-
- Username: - setUsername(e.target.value)} required /> -
-
- Password: - setPassword(e.target.value)} required /> -
- -
+ return ( +
+

Login

+ {error &&

{error}

} +
+
+ + setUsername(e.target.value)} + required + />
- ); +
+ + setPassword(e.target.value)} + required + /> +
+ +
+
+ ); } -export default Login; \ No newline at end of file +export default Login; -- cgit v1.2.3-59-g8ed1b