Reputation: 63
When using Google Identity Services (GSI) I can display a popup to ask users to connect with their Google account. This is pretty well documented and it works well with this code:
const client = window.google.accounts.oauth2.initCodeClient({
client_id: 'CLIENT_ID',
scope: 'SCOPE',
ux_mode: 'popup',
callback: async (response) => {
console.log('Response Google', response);
},
});
client.requestCode();
However, I wish to do something if the user close the popup. I can't find anything in the documentation and in examples online. I tried intermediate_iframe_close_callback
and native_callback
, but neither are called when closing the popup.
So, is it possible ? How can I do it ?
Thanks
Upvotes: 6
Views: 1832
Reputation: 161
I think the callback name is "error_callback". You can find details at: Handle Errors
const client = google.accounts.oauth2.initCodeClient({
client_id: 'YOUR_GOOGLE_CLIENT_ID',
scope: 'https://www.googleapis.com/auth/calendar.readonly',
ux_mode: 'popup',
callback: myCallback,
error_callback: myErrorCallback // You can do something when popup window closed
});
Upvotes: 4
Reputation: 156
It appears that this is not working for the current version of GSI.
It did work for the old gapi
version and if the popup were to be closed you would get a response with the error: {error: "popup_closed_by_user"}
. As referenced in this answer: Google SSO login error: "popup_closed_by_user"
Hopefully adding the #google-oauth tag will allow someone at Google to see this and hopefully update this script.
Upvotes: 2