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

Add google signup on signup page. #776

Merged
merged 1 commit into from
Nov 4, 2024
Merged
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
12 changes: 12 additions & 0 deletions backend/routes/googleauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,16 @@ router.get(
}
);

router.get('/auth/logout', (req, res) => {
req.logout(err => {
if (err) {
return next(err);
}
req.session.destroy(() => {
res.clearCookie('connect.sid');
res.redirect('https://agro-tech-ai.vercel.app/');
});
});
});

module.exports = router;
15 changes: 13 additions & 2 deletions frontend/src/components/SignUpPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { toast, ToastContainer } from "react-toastify";
import signupImage from "../assets/SignUpImage.png";
import eyeIcon from "../assets/icons/eye.svg";
import eyeSlashIcon from "../assets/icons/eye-slash.svg";

import googleIcon from "../assets/icons/icons8-google.svg"; // Google icon for the button
const SignUpPage = () => {
const navigate = useNavigate();
const [password, setPassword] = useState("");
Expand Down Expand Up @@ -52,7 +52,7 @@ const SignUpPage = () => {

try {
const response = await axios.post(
"https://agro-tech-ai-backend-teal.vercel.app/auth/signup",
"http://localhost:8080/auth/signup",
{
firstName,
lastName,
Expand All @@ -69,6 +69,9 @@ const SignUpPage = () => {
);
}
};
const handleGoogleSignIn = () => {
window.location.href = "https://agro-tech-ai-backend-teal.vercel.app/auth/google";
};

return (
<div className="min-h-screen flex items-center justify-center bg-gradient-to-r from-blue-400 to-green-500 mt-10">
Expand Down Expand Up @@ -228,6 +231,14 @@ const SignUpPage = () => {
>
Sign Up
</button>
<button
onClick={handleGoogleSignIn}
className="w-full mt-4 py-2 flex items-center justify-center bg-white text-gray-700 border border-gray-300 rounded-md font-bold transform transition duration-300 hover:scale-105"
>
<img src={googleIcon} alt="Google" className="w-6 h-6 mr-2" />
Sign in with Google
</button>

</div>
</form>
<p className="text-center text-sm mt-4">
Expand Down
Loading