diff --git a/modules/services/osm.js b/modules/services/osm.js index ef221fe90..ed30a3bbb 100644 --- a/modules/services/osm.js +++ b/modules/services/osm.js @@ -568,6 +568,11 @@ export default { }, + getUrlRoot: function() { + return urlroot; + }, + + changesetURL: function(changesetID) { return urlroot + '/changeset/' + changesetID; }, diff --git a/modules/ui/account.js b/modules/ui/account.js index 4931961cb..2d6203d70 100644 --- a/modules/ui/account.js +++ b/modules/ui/account.js @@ -54,6 +54,7 @@ export function uiAccount(context) { .on('click', e => { e.preventDefault(); osm.logout(); + tryLogout(); }); } else { // no user @@ -74,6 +75,29 @@ export function uiAccount(context) { } + // OAuth2's idea of "logout" is just to get rid of the bearer token. + // If we try to "login" again, it will just grab the token again. + // What a user probably _really_ expects is to logout of OSM so that they can switch users. + function tryLogout() { + if (!osm) return; + + const url = osm.getUrlRoot() + '/logout?referer=%2Flogin'; + // Create a 600x550 popup window in the center of the screen + const w = 600; + const h = 550; + const settings = [ + ['width', w], + ['height', h], + ['left', window.screen.width / 2 - w / 2], + ['top', window.screen.height / 2 - h / 2], + ] + .map(x => x.join('=')) + .join(','); + + window.open(url, '_blank', settings); + } + + return function(selection) { if (!osm) return;