I am trying to implement google sign-in in React. Here's my component -
import { Fragment, useEffect } from "react";
import { GOOGLE_CLIENT_ID } from "./some-file";
const GoogleSignIn = () => {
const googleSignInHandler = response => {
console.log(response);
}
const initGsi = () => {
if(window.google) {
window.google.accounts.id.initialize({
client_id: GOOGLE_CLIENT_ID,
callback: googleSignInHandler
});
}
}
useEffect(() => {
initGsi();
}, []);
return (
<Fragment>
<div
id="g_id_onload"
data-client_id={GOOGLE_CLIENT_ID}
data-context="use"
data-ux_mode="popup"
data-auto_prompt="false"
></div>
<div
className={['g_id_signin', 'gsignin'].join(' ')}
data-type="standard"
data-shape="rectangular"
data-theme="filled_blue"
data-text="continue_with"
data-callback={googleSignInHandler}
data-size="large"
data-logo_alignment="left"
></div>
</Fragment>
);
};
export default GoogleSignIn;
`
Apparently it works if I set data-auto_prompt="true"
ie one-tap. But, I don't know how to make it work for the button click. I really don't want to use an npm package, besides they are also based on legacy Google sign-in. Is there a way?