From 99e8a0e5360f397c5bbac5ae1a952cba98cf54fb Mon Sep 17 00:00:00 2001 From: Biswakalyan Bhuyan Date: Thu, 25 Jul 2024 23:29:15 +0530 Subject: added login and registation methods --- src/pages/Login.jsx | 34 ++++++++++++++++++++++++++++------ src/pages/Register.jsx | 32 +++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 11 deletions(-) (limited to 'src/pages') 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 (

Login

- - + setUsername(e.target.value)} + /> + setPassword(e.target.value)} + />
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 (

Register

- - + setUsername(e.target.value)} + /> + setPassword(e.target.value)} + />
-- cgit v1.2.3-59-g8ed1b