import React, { useState } from "react";
import { useHistory } from "react-router-dom";
import { signInWithGoogle } from "./firebase/auth"; // import your Google sign-in function
function SignInPage() {
const [loading, setLoading] = useState(false);
const history = useHistory(); // get the history object from React Router
const handleSignInWithGoogle = async () => {
setLoading(true);
try {
await signInWithGoogle(); // call your Google sign-in function
setLoading(false);
history.push("/"); // redirect to the homepage
} catch (error) {
setLoading(false);
console.log(error);
}
};
return (
<div>
<button onClick={handleSignInWithGoogle} disabled={loading}>
Sign in with Google
</button>
</div>
);
}
export default SignInPage;