Login with Google: How to programmatically open prompt for user consent and get the CredentialResponse on success

1.8k Views Asked by At

I am trying to trigger the Prompt for User Consent to open on clicking a custom html button rather than the Login iframe button rendered by Google. I am using Sign In With Google JavaScript API and I didn't found a function to do this, but I found a way to do this using the token model and using the Code Model but these gives me token/code in the callback, but I need a CredentialResponse in callback, is there any way to do this ? I am trying to create Vue/React plugins to easily implement Sign In With Google,One-tap sign-up and Automatic sign-in features in Vue/React applications, but I am stuck now.

1

There are 1 best solutions below

2
Mo'men Sherif On

you can use @react-oauth/google it uses the new google service identity SDK, with useGoogleLogin() custom hook it can be used with your custom button.

and you can check the implementation of the hook to do the same work in vue