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 ( -
+
{/* Logo and Title */} - -
+
Station Saarthi Logo -

+

Station Saarthi

-

+

Your Trusted Platform Guide

@@ -83,104 +133,117 @@ const Login = () => {
{/* Login Heading */} -

+

Login

{/* Success Message */} {loginSuccess && ( -

+

Login successful! Welcome back.

)} {/* Username Input */} -
+
setUsername(e.target.value)} - placeholder='Enter your username' - className='w-full px-4 py-2 transition duration-300 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500' + placeholder="Enter your username" + className="w-full px-4 py-2 transition duration-300 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" required /> {errors.username && ( -
{errors.username}
+
{errors.username}
)}
{/* Password Input */} -
+
setPassword(e.target.value)} - placeholder='Enter your password' - className='w-full px-4 py-2 transition duration-300 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500' + placeholder="Enter your password" + className="w-full px-4 py-2 transition duration-300 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" required />{" "} {errors.password && ( -
{errors.password}
+
{errors.password}
)}
{/* Login Button */} - - {/* Forgot Password Link */} -

- -

+
+
+ or +
+
- {/* Don't have an account link */} -

- Don't have an account?{" "} - -

+
+ +
+ + {/* Forgot Password Link */} +

+ +

+ + {/* Don't have an account link */} +

+ Don't have an account?{" "} + +

+
); };