aboutsummaryrefslogtreecommitdiffstats
path: root/src/pages/Login.jsx
diff options
context:
space:
mode:
authorLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2024-07-25 23:29:15 +0530
committerLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2024-07-25 23:29:15 +0530
commit99e8a0e5360f397c5bbac5ae1a952cba98cf54fb (patch)
tree9d68d3c9f1e46dd137d75b99f43764af47de56fd /src/pages/Login.jsx
parent680f38b1c48c4cc5c4b34b285f68fe48217d0ab9 (diff)
downloadadmin-panel-99e8a0e5360f397c5bbac5ae1a952cba98cf54fb.tar.gz
admin-panel-99e8a0e5360f397c5bbac5ae1a952cba98cf54fb.tar.bz2
admin-panel-99e8a0e5360f397c5bbac5ae1a952cba98cf54fb.zip
added login and registation methods
Diffstat (limited to 'src/pages/Login.jsx')
-rw-r--r--src/pages/Login.jsx34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/pages/Login.jsx b/src/pages/Login.jsx
index 89e0c8b..9d38aa9 100644
--- a/src/pages/Login.jsx
+++ b/src/pages/Login.jsx
@@ -1,20 +1,42 @@
-import React from 'react';
+import React, { useState } from 'react';
+import axios from 'axios';
import { useNavigate } from 'react-router-dom';
const Login = () => {
+ const [username, setUsername] = useState('');
+ const [password, setPassword] = useState('');
const navigate = useNavigate();
- const handleLogin = () => {
- // Handle login logic here
- navigate('/dashboard');
+ const handleLogin = async (e) => {
+ e.preventDefault();
+ try {
+ const response = await axios.post('http://localhost:5000/login', {
+ username,
+ password,
+ });
+ localStorage.setItem('token', response.data.token);
+ navigate('/dashboard');
+ } catch (error) {
+ console.error(error);
+ }
};
return (
<div>
<h1>Login</h1>
<form onSubmit={handleLogin}>
- <input type="text" placeholder="Username" />
- <input type="password" placeholder="Password" />
+ <input
+ type="text"
+ placeholder="Username"
+ value={username}
+ onChange={(e) => setUsername(e.target.value)}
+ />
+ <input
+ type="password"
+ placeholder="Password"
+ value={password}
+ onChange={(e) => setPassword(e.target.value)}
+ />
<button type="submit">Login</button>
</form>
</div>