Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #340 Corrected the disfucntional google login button #503

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"boxicons": "^2.1.4",
"jwt-decode": "^4.0.0",
"lottie-react": "^2.4.0",

"react": "^18.2.0",
"react-bootstrap": "^2.10.2",
"react-chatbot-kit": "^2.2.2",
Expand Down
104 changes: 55 additions & 49 deletions src/Components/Login/Login.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, { useState } from "react";
import { useNavigate, NavLink } from "react-router-dom";
import "./Login.css";
import { GoogleLogin } from "@react-oauth/google";
import {jwtDecode} from "jwt-decode";
import { GoogleOAuthProvider, GoogleLogin } from '@react-oauth/google';

const Login = () => {
const [email, setEmail] = useState("");
Expand Down Expand Up @@ -36,57 +35,64 @@ const Login = () => {
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
};

const handleGoogleLoginSuccess = (credentialResponse) => {
const credentialDecoded = jwt_decode(credentialResponse.credential);
console.log("Google Login Success:", credentialDecoded);
navigate("/explore");
};

const handleGoogleLoginFailure = () => {
console.log("Login Failed");
};

return (
<div className="login-outerContainer">
<div className="login-container">
<h2>Login</h2>
<div className="input">
<input
type="email"
placeholder="Email"
value={email}
onChange={(e) => {
setEmail(e.target.value);
setWarnings((prevWarnings) => ({ ...prevWarnings, email: "" }));
}}
onBlur={(e) => {
if (!validateEmail(e.target.value)) {
setWarnings((prevWarnings) => ({ ...prevWarnings, email: "*Please enter a valid email address!" }));
}
}}
/>
{warnings.email && <p style={{ color: "red" }} className="warningmsg">{warnings.email}</p>}
<input
type="password"
placeholder="Password"
value={password}
onChange={(e) => {
setPassword(e.target.value);
setWarnings((prevWarnings) => ({ ...prevWarnings, password: "" }));
}}
onBlur={(e) => {
if (!e.target.value) {
setWarnings((prevWarnings) => ({ ...prevWarnings, password: "*Please enter your password" }));
}
}}
<GoogleOAuthProvider clientId="YOUR_GOOGLE_CLIENT_ID">
<div className="login-outerContainer">
<div className="login-container">
<h2>Login</h2>
<div className="input">
<input
type="email"
placeholder="Email"
value={email}
onChange={(e) => {
setEmail(e.target.value);
setWarnings((prevWarnings) => ({ ...prevWarnings, email: "" }));
}}
onBlur={(e) => {
if (!validateEmail(e.target.value)) {
setWarnings((prevWarnings) => ({ ...prevWarnings, email: "*Please enter a valid email address!" }));
}
}}
/>
{warnings.email && <p style={{ color: "red" }} className="warningmsg">{warnings.email}</p>}
<input
type="password"
placeholder="Password"
value={password}
onChange={(e) => {
setPassword(e.target.value);
setWarnings((prevWarnings) => ({ ...prevWarnings, password: "" }));
}}
onBlur={(e) => {
if (!e.target.value) {
setWarnings((prevWarnings) => ({ ...prevWarnings, password: "*Please enter your password" }));
}
}}
/>
{warnings.password && <p style={{ color: "red" }} className="warningmsg">{warnings.password}</p>}
</div>
<button onClick={handleLogin}>Login</button>
<p>
Don't have an account? <NavLink to="/signup">Sign up</NavLink>
</p>
<GoogleLogin
onSuccess={handleGoogleLoginSuccess}
onError={handleGoogleLoginFailure}
/>
{warnings.password && <p style={{ color: "red" }} className="warningmsg">{warnings.password}</p>}
</div>
<button onClick={handleLogin}>Login</button>
<p>
Don't have an account? <NavLink to="/signup">Sign up</NavLink>
</p>
<GoogleLogin
onSuccess={(credentialResponse) => {
const credentialDecoded = jwtDecode(credentialResponse.credential);
console.log(credentialDecoded);
}}
onError={() => {
console.log("Login Failed");
}}
/>
</div>
</div>
</GoogleOAuthProvider>
);
};

Expand Down