aboutsummaryrefslogtreecommitdiffstats
path: root/src/pages
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
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')
-rw-r--r--src/pages/Login.jsx34
-rw-r--r--src/pages/Register.jsx32
2 files changed, 55 insertions, 11 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>
diff --git a/src/pages/Register.jsx b/src/pages/Register.jsx
index 84c0bf2..f0acf58 100644
--- a/src/pages/Register.jsx
+++ b/src/pages/Register.jsx
@@ -1,17 +1,39 @@
-import React from 'react';
+import React, { useState } from 'react';
+import axios from 'axios';
const Register = () => {
- const handleRegister = (e) => {
+ const [username, setUsername] = useState('');
+ const [password, setPassword] = useState('');
+
+ const handleRegister = async (e) => {
e.preventDefault();
- // Handle registration logic here
+ try {
+ const response = await axios.post('http://localhost:5000/register', {
+ username,
+ password,
+ });
+ console.log(response.data);
+ } catch (error) {
+ console.error(error);
+ }
};
return (
<div>
<h1>Register</h1>
<form onSubmit={handleRegister}>
- <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">Register</button>
</form>
</div>