diff --git a/client/app/page.js b/client/app/page.js index 3fdcb94..285fdce 100644 --- a/client/app/page.js +++ b/client/app/page.js @@ -1,34 +1,34 @@ 'use client' -import React from 'react' -import Link from 'next/link' -import Router from 'next/router'; -import { EyeNoneIcon, EyeOpenIcon } from '@radix-ui/react-icons' - +import React from 'react'; import { useRouter } from 'next/navigation'; import { useState } from 'react'; import axios from 'axios'; import { ToastContainer, toast } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; +import { EyeNoneIcon, EyeOpenIcon } from '@radix-ui/react-icons'; const page = () => { const router = useRouter(); - const [loginData, setloginData] = useState({ + const [loginData, setLoginData] = useState({ email: '', password: '' - }) - const [newUser, setnewUser] = useState({ - username:"", - email:"", - password:"" - }) + }); + const [newUser, setNewUser] = useState({ + username: "", + email: "", + password: "", + confirmPassword: "" // Added confirmPassword + }); const [loginHeight, setLoginHeight] = useState('100%'); const [signupHeight, setSignupHeight] = useState('10%'); const [showLoginForm, setShowLoginForm] = useState(true); const [showSignupForm, setShowSignupForm] = useState(false); - const[showPassword,setshowPassword] = useState(false); - const handleeyeclick=()=>{ - setshowPassword(!showPassword); - } + const [showPassword, setShowPassword] = useState(false); + + const handleEyeClick = () => { + setShowPassword(!showPassword); + }; + const notify = (message) => toast(message, { position: "bottom-left", autoClose: 5000, @@ -38,7 +38,6 @@ const page = () => { draggable: true, progress: undefined, theme: "dark", - // transition: Bounce, }); const getCookieValue = (name) => { @@ -64,76 +63,75 @@ const page = () => { setSignupHeight('100%'); setShowLoginForm(false); setShowSignupForm(true); - - }; - + const handleSubmit = (e) => { - e.preventDefault(); - loginUser(loginData); - } + e.preventDefault(); + loginUser(loginData); + }; + const handleChange = (e) => { - const { name, value } = e.target; - setloginData({ - ...loginData, - [name]: value, - }); - } + const { name, value } = e.target; + setLoginData({ + ...loginData, + [name]: value, + }); + }; + const loginUser = async (credentials) => { - try { - const res = await axios.post("https://investra-26xe.vercel.app/login", credentials); -// const res = await axios.post("http://localhost:4000/login", loginData) - if (res.data.message === 'Login Successful') { - const userData = JSON.stringify(res.data) - //sessionStorage.setItem('jwt', res.data.jwt); - //sessionStorage.setItem('activeUser',userData) - document.cookie = "jwt="+res.data.jwt+"; path=/"; - document.cookie = "activeUser="+userData+"; path=/"; - const cookies = document.cookie.split(';').map(cookie => cookie.trim()); - console.log(getCookieValue('jwt')); - router.push('/Dash'); - } - } catch (error) { - notify(error.response.data) - console.log(error); + try { + const res = await axios.post("https://investra-26xe.vercel.app/login", credentials); + if (res.data.message === 'Login Successful') { + const userData = JSON.stringify(res.data); + document.cookie = "jwt=" + res.data.jwt + "; path=/"; + document.cookie = "activeUser=" + userData + "; path=/"; + router.push('/Dash'); } - } + } catch (error) { + notify(error.response.data); + console.log(error); + } + }; const handleSubmit2 = (e) => { - e.preventDefault(); - signupUser(); - } + e.preventDefault(); + signupUser(); + }; + const handleChange2 = (e) => { const { name, value } = e.target; - setnewUser({ + setNewUser({ ...newUser, [name]: value, }); - } - const signupUser = async() => { + }; + + const signupUser = async () => { + if (newUser.password !== newUser.confirmPassword) { + notify("Passwords do not match"); + return; + } + try { - const res = await axios.post("https://investra-26xe.vercel.app/signup", newUser); - if (res.data.message === "User added successfully") { - const userData = JSON.stringify(res.data) - document.cookie = "jwt="+res.data.jwt+"; path=/"; - document.cookie = "activeUser="+userData+"; path=/"; - await loginUser(userData); - } + const res = await axios.post("https://investra-26xe.vercel.app/signup", newUser); + if (res.data.message === "User added successfully") { + const userData = JSON.stringify(res.data); + document.cookie = "jwt=" + res.data.jwt + "; path=/"; + document.cookie = "activeUser=" + userData + "; path=/"; + await loginUser(newUser); // Update to use newUser for login + } } catch (error) { - console.error(error); - notify("Signup failed. Please try again."); + console.error(error); + notify("Signup failed. Please try again."); } - } + }; - const showForgetPage=() => - { - //e.preventDefault(); + const showForgetPage = () => { router.push('/Forget-Password'); - } + }; return ( <> - {/* Your existing JSX */} { draggable pauseOnHover theme="dark" - /> + />
Investra -

+

- -- a place to grow -- + -- a place to grow --

-
-
+
+
Login -
- - - + + + { transform: 'translateY(-50%)', cursor: 'pointer' }} - > - {showPassword ? : } - - - -
Forget Password
+ > + {showPassword ? : } +
+ + +
+ Forget Password
+
-
-
-
+
+
+ Signup - - - + + + { transform: 'translateY(-50%)', cursor: 'pointer' }} - > - {showPassword ? : } - - - -
+ > + {showPassword ? : } + + + + +
@@ -247,5 +254,4 @@ const page = () => { ); }; - -export default page \ No newline at end of file +export default page;