aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/Login.js78
1 files changed, 44 insertions, 34 deletions
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 (
- <div className="Login">
- <h2>Login</h2>
- {error && <p style={{ color: 'red' }}>{error}</p>}
- <form onSubmit={handleSubmit}>
- <div>
- <lable>Username:</lable>
- <input type="text" value={username} onChange={(e) => setUsername(e.target.value)} required />
- </div>
- <div>
- <lable>Password:</lable>
- <input type="password" value={password} onChange={(e) => setPassword(e.target.value)} required />
- </div>
- <button type="submit">Login</button>
- </form>
+ return (
+ <div className="Login">
+ <h2>Login</h2>
+ {error && <p style={{ color: 'red' }}>{error}</p>}
+ <form onSubmit={handleSubmit}>
+ <div>
+ <label>Username:</label>
+ <input
+ type="text"
+ value={username}
+ onChange={(e) => setUsername(e.target.value)}
+ required
+ />
</div>
- );
+ <div>
+ <label>Password:</label>
+ <input
+ type="password"
+ value={password}
+ onChange={(e) => setPassword(e.target.value)}
+ required
+ />
+ </div>
+ <button type="submit">Login</button>
+ </form>
+ </div>
+ );
}
-export default Login; \ No newline at end of file
+export default Login;