diff --git a/.changeset/fix-myuplink-test-oauth.md b/.changeset/fix-myuplink-test-oauth.md new file mode 100644 index 00000000..283cf0f5 --- /dev/null +++ b/.changeset/fix-myuplink-test-oauth.md @@ -0,0 +1,5 @@ +--- +"ftw": patch +--- + +Start the MyUplink OAuth connection flow when Test connection is used before authorization, instead of running a probe that cannot succeed without a refresh token. diff --git a/web/settings/tabs/devices.js b/web/settings/tabs/devices.js index d08ca6ba..303386b3 100644 --- a/web/settings/tabs/devices.js +++ b/web/settings/tabs/devices.js @@ -2240,6 +2240,26 @@ ctx.captureCurrentTab(); var driver = config.drivers && config.drivers[dIdx]; if (!driver) return; + + // Authorization-code drivers such as MyUplink cannot be probed until + // the one-time OAuth consent has produced a refresh token. Treat + // "Test connection" as the next setup action instead of running a + // probe that is guaranteed to fail: start the existing Connect flow. + var oauthConnectBtn = bodyEl.querySelector('.myuplink-connect-btn[data-driver-idx="' + dIdx + '"]'); + var refreshToken = driver.config && driver.config.refresh_token; + if (oauthConnectBtn && (typeof refreshToken !== "string" || refreshToken === "")) { + if (statusEl) { + statusEl.textContent = "Authorization required"; + statusEl.className = "driver-test-status"; + } + if (outputEl) { + outputEl.hidden = false; + outputEl.innerHTML = '