From add513f39e814335014e12e6eac2a254d9a2c8f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ky=E2=84=93e=20Hensel?= Date: Thu, 23 Jan 2025 03:25:56 +1100 Subject: [PATCH] fix confusing behaviour after logging out in the standalone build of iD (#10683) when user logs out of osm.org via the logout button: the popup continues to the login screen, which if completed now logs the user back into iD with the new credentials --- CHANGELOG.md | 2 ++ modules/services/osm.js | 5 +++-- modules/ui/account.js | 30 ++++++------------------------ 3 files changed, 11 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37891ba18..0d99cdceb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ _Breaking developer changes, which may affect downstream projects or sites that * Fix grid lines from showing up on background map tiles in certain situations (semi-transparent tiles or fractional browser zoom level) ([#10594], thanks [@Nekzuris]) * Prevent search results from sometimes getting stuck in the highlighted state when mouse-hovering the list of search results while typing ([#10661]) * Allow tiles in minimap to be slightly underzoomed, preventing them from blacking out on low map zoom levels ([#10653]) +* Fix confusing behaviour after logging out in the standalone build of iD ([#10683], thanks [@k-yle]) #### :earth_asia: Localization * Update Sinitic languages in the Multilingual Names field ([#10488], thanks [@winstonsung]) * Update the list of languages in the Wikipedia field ([#10489]) @@ -74,6 +75,7 @@ _Breaking developer changes, which may affect downstream projects or sites that [#10634]: https://github.com/openstreetmap/iD/issues/10634 [#10650]: https://github.com/openstreetmap/iD/issues/10650 [#10653]: https://github.com/openstreetmap/iD/issues/10653 +[#10683]: https://github.com/openstreetmap/iD/issues/10683 [#10684]: https://github.com/openstreetmap/iD/pull/10684 [@winstonsung]: https://github.com/winstonsung/ [@Nekzuris]: https://github.com/Nekzuris diff --git a/modules/services/osm.js b/modules/services/osm.js index 07baebe20..9004a7410 100644 --- a/modules/services/osm.js +++ b/modules/services/osm.js @@ -1417,7 +1417,8 @@ export default { }, - authenticate: function(callback) { + /** @param {import('osm-auth').LoginOptions} options */ + authenticate: function(callback, options) { var that = this; var cid = _connectionID; _userChangesets = undefined; @@ -1444,7 +1445,7 @@ export default { locale: localizer.localeCode(), }); - oauth.authenticate(done); + oauth.authenticate(done, options); }, diff --git a/modules/ui/account.js b/modules/ui/account.js index 84f61733b..ee4fee1b0 100644 --- a/modules/ui/account.js +++ b/modules/ui/account.js @@ -54,7 +54,12 @@ export function uiAccount(context) { .on('click', e => { e.preventDefault(); osm.logout(); - tryLogout(); + // 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. + // So, we open a popup with a "Logout" button. After logging out, they can login again using + // the same popup window. + osm.authenticate(undefined, { switchUser: true }); }); } else { // no user @@ -75,29 +80,6 @@ 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;