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

Added Sign in with Google under issue #340 #515

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion Frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
<script src="https://accounts.google.com/gsi/client" async></script>
</body>
<div class="circle-container">
<div class="circle"></div>
Expand Down Expand Up @@ -90,4 +91,4 @@

</script>

</html>
</html>
4 changes: 4 additions & 0 deletions Frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
"@emotion/styled": "^11.11.5",
"@mui/icons-material": "^5.15.18",
"@mui/material": "^5.15.18",
"@react-oauth/google": "^0.12.1",
"axios": "^1.5.0",
"fuse.js": "^7.0.0",
"gapi-script": "^1.2.0",
"jwt-decode": "^4.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-google-login": "^5.2.2",
"react-google-recaptcha": "^3.1.0",
"react-hot-toast": "^2.4.1",
"react-icons": "^5.2.1",
Expand Down
35 changes: 33 additions & 2 deletions Frontend/src/Pages/Profile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import RemoveRedEyeIcon from "@mui/icons-material/RemoveRedEye";
import VisibilityOffIcon from "@mui/icons-material/VisibilityOff"
import { FormLoader } from "../Components/Loader";
import convertToBase64 from "./convertToBase64";
import {GoogleOAuthProvider, GoogleLogin } from "@react-oauth/google";
import {jwtDecode} from "jwt-decode";

// components
import toast from 'react-hot-toast';
import Error from "../Components/Error";
import UserProfile from "./UserProfile";
import { useCart } from "../Components/CartContext";
import ".././CSS/Profile.css";
import "../CSS/Profile.css";
import Reg from "/reg.png";

const Profile = () => {
Expand All @@ -34,7 +36,18 @@ const Profile = () => {
const backendUrl = "https://ecommerce-backend-0wr7.onrender.com/";

const [file, setFile] = useState(null);

const responseMessage = (credentialResponse) => {
const credentialDecoded = jwtDecode(credentialResponse.credential);
console.log("Google Login Success:", credentialDecoded);
navigate("/home");
};

const errorMessage = (error) => {

console.log(error);
console.log("Failed to login");
};
useEffect(() => {
const token = localStorage.getItem("token");
const userData = localStorage.getItem("userData");
Expand Down Expand Up @@ -207,7 +220,12 @@ const Profile = () => {
<div className="profile-outer_box">
<div className="profile-card" style={{ boxShadow: "25px 25px 100px rgba(0, 0, 0, 0.2)" }}>
<h2>{isLogin ? "Login" : "Sign Up"}</h2>
<script
src="https://accounts.google.com/gsi/client"
async
></script>
{isLogin ? (
<GoogleOAuthProvider clientId="758500021538-7tm7mv4tas3ouma9bb0uau1ia209al78.apps.googleusercontent.com">
<form onSubmit={handleLoginFormSubmit}>
<div className="input-group">
<EmailIcon className="icon"
Expand Down Expand Up @@ -241,8 +259,20 @@ const Profile = () => {
<button type="submit" disabled={isLoading}>
{isLoading ? <FormLoader /> : "Login"}
</button>

<div
style={{
marginTop: 20,
display: "flex",
justifyContent: "center",
}}
>
<GoogleLogin
onSuccess={responseMessage}
onError={errorMessage}
/>
</div>
</form>
</GoogleOAuthProvider>
) : (
<form onSubmit={handleSignupFormSubmit}>

Expand Down Expand Up @@ -311,6 +341,7 @@ const Profile = () => {
: "Already have an account? Login"}
</button>
</div>

</div>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions Frontend/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import FeedbackButton from "./Components/Feedbtn";

ReactDOM.createRoot(document.getElementById("root")).render(
<React.StrictMode>
<GoogleOAuthProvider clientId="758500021538-7tm7mv4tas3ouma9bb0uau1ia209al78.apps.googleusercontent.com">
<CartProvider>
<BrowserRouter>
<App />
<FeedbackButton />
</BrowserRouter>
</CartProvider>
</GoogleOAuthProvider>
</React.StrictMode>
);