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

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