Javascript Adapter - Reject 'login' promise when users close their cordova in-app-browser on purpose (#5000)

This commit is contained in:
Lorent Lempereur 2018-05-10 00:49:38 +02:00 committed by Stian Thorgersen
parent 1258923a0d
commit 27d8afe4a7

View file

@ -1224,11 +1224,17 @@
var ref = cordovaOpenWindowWrapper(loginUrl, '_blank', cordovaOptions); var ref = cordovaOpenWindowWrapper(loginUrl, '_blank', cordovaOptions);
var completed = false; var completed = false;
var closed = false;
var closeBrowser = function() {
closed = true;
ref.close();
};
ref.addEventListener('loadstart', function(event) { ref.addEventListener('loadstart', function(event) {
if (event.url.indexOf('http://localhost') == 0) { if (event.url.indexOf('http://localhost') == 0) {
var callback = parseCallback(event.url); var callback = parseCallback(event.url);
processCallback(callback, promise); processCallback(callback, promise);
ref.close(); closeBrowser();
completed = true; completed = true;
} }
}); });
@ -1238,15 +1244,23 @@
if (event.url.indexOf('http://localhost') == 0) { if (event.url.indexOf('http://localhost') == 0) {
var callback = parseCallback(event.url); var callback = parseCallback(event.url);
processCallback(callback, promise); processCallback(callback, promise);
ref.close(); closeBrowser();
completed = true; completed = true;
} else { } else {
promise.setError(); promise.setError();
ref.close(); closeBrowser();
} }
} }
}); });
ref.addEventListener('exit', function(event) {
if (!closed) {
promise.setError({
reason: "closed_by_user"
});
}
});
return promise.promise; return promise.promise;
}, },