diff --git a/frontend/src/Pages/LoginPage.jsx b/frontend/src/Pages/LoginPage.jsx index 06790ca..759895e 100644 --- a/frontend/src/Pages/LoginPage.jsx +++ b/frontend/src/Pages/LoginPage.jsx @@ -5,6 +5,7 @@ import backicon from "../assets/svg/backicon.svg"; // Assuming you have a back i import { loginValidation } from "../validations/validation"; import { MdOutlinePassword } from "react-icons/md"; import { FaUser } from "react-icons/fa"; +import { GoogleLogin } from "@react-oauth/google"; const Login = () => { useEffect(() => { @@ -17,6 +18,55 @@ const Login = () => { const [passwordVisible, setPasswordVisible] = useState(false); // State for password visibility const navigate = useNavigate(); + // Handle Google success + const handleGoogleLoginSuccess = async (credentialResponse) => { + const token = credentialResponse.credential; + + // Decode the token to extract user information + const decoded = jwtDecode(token); + console.log("Decoded Google Token:", decoded); + + try { + const response = await fetch( + "https://stationguide.onrender.com/api/register", + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: decoded.name, + phoneNumber: phoneNumber ? phoneNumber : "", + email: decoded.email, + password: "", + isGoogle: true, + }), + } + ); + + const data = await response.json(); + + if (response.ok) { + setConfirmationMessage( + "Your account is created successfully. Please login to access the website." + ); + setUserName(""); // Reset username + setPhoneNumber(""); + setEmail(""); + setPassword(""); + } else { + setConfirmationMessage(`Error: ${data.error}`); + } + } catch (error) { + console.error("Error registering with Google:", error); + } + }; + + // Handle Google failure + const handleGoogleLoginFailure = () => { + console.log("Google Sign-In failed"); + }; + const togglePasswordVisibility = () => { setPasswordVisible(!passwordVisible); // Toggle password visibility }; @@ -60,21 +110,21 @@ const Login = () => { }; return ( -