From c00ac1ff51c795d4d93c32e0a913e2cebf917d0c Mon Sep 17 00:00:00 2001 From: Biswakalyan Bhuyan Date: Thu, 25 Jul 2024 12:09:28 +0530 Subject: added backend and login portal --- src/components/Login.js | 43 +++++++++++++++++++++++++++++++++++++++++++ src/components/MyComponent.js | 7 +++++++ 2 files changed, 50 insertions(+) create mode 100644 src/components/Login.js create mode 100644 src/components/MyComponent.js (limited to 'src/components') diff --git a/src/components/Login.js b/src/components/Login.js new file mode 100644 index 0000000..620ece0 --- /dev/null +++ b/src/components/Login.js @@ -0,0 +1,43 @@ +import React, { useState } from 'react'; +import axios from 'axios'; + +function Login() { + 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); + } + }; + + return ( +
+

Login

+ {error &&

{error}

} +
+
+ Username: + setUsername(e.target.value)} required /> +
+
+ Password: + setPassword(e.target.value)} required /> +
+ +
+
+ ); +} + +export default Login; \ No newline at end of file diff --git a/src/components/MyComponent.js b/src/components/MyComponent.js new file mode 100644 index 0000000..b9434ea --- /dev/null +++ b/src/components/MyComponent.js @@ -0,0 +1,7 @@ +import React from 'react'; + +function MyComponent() { + return
This is my component!
; +} + +export default MyComponent; \ No newline at end of file -- cgit v1.2.3-59-g8ed1b