diff --git a/src/Pages/Login.tsx b/src/Pages/Login.tsx index 9db1596..4253c8f 100644 --- a/src/Pages/Login.tsx +++ b/src/Pages/Login.tsx @@ -1,45 +1,45 @@ -import { Center, HStack, Image, Input, Text, VStack } from "@chakra-ui/react" -import axios from "axios" -import { useContext, useState } from "react" -import { useForm } from "react-hook-form" -import { useDispatch } from "react-redux" -import GlobalStateContext from "../Contexts/GlobalStateContext" -import { setToken } from "../Redux/Service/authSlice" -import logo from '../assets/logo.svg' -import { Button } from "../components/ui/button" -import { Field } from "../components/ui/field" -import { Toaster } from "../components/ui/toaster" -import { PasswordInput } from "../components/ui/password-input" -import { useNavigate } from "react-router-dom" +import { Center, HStack, Image, Input, Text, VStack } from "@chakra-ui/react"; +import axios from "axios"; +import { useContext, useState } from "react"; +import { useForm } from "react-hook-form"; +import { useDispatch } from "react-redux"; +import GlobalStateContext from "../Contexts/GlobalStateContext"; +import { setToken } from "../Redux/Service/authSlice"; +import logo from "../assets/logo.svg"; +import { Button } from "../components/ui/button"; +import { Field } from "../components/ui/field"; +import { Toaster } from "../components/ui/toaster"; +import { PasswordInput } from "../components/ui/password-input"; +import { useNavigate } from "react-router-dom"; interface FormValues { - mobileNumber: number - password: string + mobileNumber: number; + password: string; } const Login = () => { - const navigate = useNavigate() - const dispatch = useDispatch() - const [isLoading, setIsLoading] = useState(false) + const navigate = useNavigate(); + const dispatch = useDispatch(); + const [isLoading, setIsLoading] = useState(false); const context = useContext(GlobalStateContext); if (!context) { - throw new Error('App must be used within a GlobalStateProvider'); + throw new Error("App must be used within a GlobalStateProvider"); } const { setIsAuthenticate } = context; const { register, handleSubmit, formState: { errors }, - } = useForm() + } = useForm(); const onSubmit = handleSubmit(async (data) => { setIsLoading(true); - + // Encode Basic Auth Credentials - const username = import.meta.env.VITE_USER_NAME||''; // Replace with actual username - const password = import.meta.env.VITE_PASSWORD||''; // Replace with actual password + const username = import.meta.env.VITE_USER_NAME || ""; // Replace with actual username + const password = import.meta.env.VITE_PASSWORD || ""; // Replace with actual password const basicAuth = `${username} : ${password}`; // Encode to Base64 - + try { const res = await axios.post( `${import.meta.env.VITE_API_URL}/login`, @@ -56,84 +56,119 @@ const Login = () => { ); if (res.data) { - setIsAuthenticate(true) - console.log('===================================='); + setIsAuthenticate(true); + console.log("===================================="); console.log(res.data?.data); - console.log('===================================='); - navigate('/') + console.log("===================================="); + navigate("/"); dispatch(setToken(String(res.data?.data["access-token"]))); } else { - console.log("===================================="); console.log(res); console.log("===================================="); - } - } catch (error) { if (error) { - console.error("Login failed", error); - setIsLoading(false) - + setIsLoading(false); } } }); - - - return ( - - - - - + + - - - - - - - -
+ +
+
+ + + LOGIN + - - - -
- - LOGIN - - - - - {/* Forget password */} + + + + {/* Forget password */} - - - {/* Forget password */} + + + {/* Forget password */} - + Forgot password - -
- ) -} + ); +}; -export default Login \ No newline at end of file +export default Login;