javascript - How to determine if google auth2.signIn() window was closed by the user? -


im implementing auth using , showing loading icon in react when user clicks button sign in , auth2 account selection/login window shows.

however if user closes window, there doesnt seem event fired i.e signin() function returns promise never resolves, have thought google return error promise if window closed. result there no way me stop showing loader icon , reshow login menu.

i wondering if had solution this?

although api provides mechanism detecting when user clicks deny button, there not built-in way detecting user abruptly closed popup window (or exited web browser, shut down computer, , on). deny condition provided in case want re-prompt user reduced scopes (e.g. requested "email" need profile , let user proceed without giving email).

if response sign-in callback contains error, access_denied, indicates user clicked deny button:

function onsignincallback(authresult) {   if (authresult['error'] && authresult['error'] == 'access_denied') {     // user explicitly denied application's requested scopes   } } 

you should able implement sign-in without detecting whether window closed; demonstrated in virtually all of google+ sample apps. in short, should avoid using spinner you're doing , instead should hide authenticated ui until user has signed in.

it's not recommended this, implement detection of pop-up closing, override global window.open call, detect in window.unload or poll whether window closed without user authenticating:

var lastopenedwindow = undefined; window.open = function (open) {     return function (url, name, features) {         // set name if missing here         name = name || "default_window_name";         lastopenedwindow = open.call(window, url, name, features);         return lastopenedwindow;     }; }(window.open);  var intervalhandle = undefined; function detectclose() {   intervalhandle = setinterval(function(){     if (lastopenedwindow && lastopenedwindow.closed) {       // todo: check user !authenticated       console.log("why did window close without auth?");       window.clearinterval(intervalhandle);     }   }, 500); } 

note i've implemented it, mechanism unreliable , subject race conditions.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -