Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trigger error if popup is closed prematurely #135

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/osm-auth.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,23 @@ export function osmAuth(o) {
window.location = url;
}
} else {
var popupClosedWatcher = setInterval(function() {
if (popup.closed) {
var error = new Error('Popup was closed prematurely');
error.status = 'popup-closed';
callback(error);
window.clearInterval(popupClosedWatcher);
delete window.authComplete;
}
}, 1000);
oauth.popupWindow = popup;
popup.location = url;
}

// Called by a function in the redirect URL page, in the popup window. The
// window closes itself.
window.authComplete = function (url) {
clearTimeout(popupClosedWatcher);
var params = utilStringQs(url.split('?')[1]);
if (params.state !== state) {
var error = new Error('Invalid state');
Expand Down
Loading