From 0755230c82f3dd7bd6761f079afdd6137c7f3090 Mon Sep 17 00:00:00 2001 From: Holger Huo <50446405+HolgerHuo@users.noreply.github.com> Date: Fri, 27 Dec 2024 00:40:17 +0800 Subject: [PATCH] Fix login with alternative domain --- src/pages/login.css | 6 +++++ src/pages/login.jsx | 52 +++++++++++++++++++++++++++++-------------- src/pages/welcome.jsx | 2 +- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/src/pages/login.css b/src/pages/login.css index 7c9273d8..35f0cf07 100644 --- a/src/pages/login.css +++ b/src/pages/login.css @@ -60,3 +60,9 @@ color: var(--text-insignificant-color); font-style: italic; } + +#settings input { + width: revert; + display: inline; + margin-top: 0.25em; +} diff --git a/src/pages/login.jsx b/src/pages/login.jsx index 9d9980ca..8b5629b0 100644 --- a/src/pages/login.jsx +++ b/src/pages/login.jsx @@ -30,10 +30,12 @@ function Login() { const [uiState, setUIState] = useState('default'); const [searchParams] = useSearchParams(); const instance = searchParams.get('instance'); + const isWebDomainParam = searchParams.get('is_web_domain'); const submit = searchParams.get('submit'); const [instanceText, setInstanceText] = useState( instance || cachedInstanceURL?.toLowerCase() || '', ); + const [isWebDomain, setIsWebDomain] = useState(isWebDomainParam || false); const [instancesList, setInstancesList] = useState([]); const searcher = useRef(); @@ -63,24 +65,28 @@ function Login() { (async () => { // WEB_DOMAIN vs LOCAL_DOMAIN negotiation time // https://docs.joinmastodon.org/admin/config/#web_domain - try { - const res = await fetch(`https://${instanceURL}/.well-known/host-meta`); // returns XML - const text = await res.text(); - // Parse XML - const parser = new DOMParser(); - const xmlDoc = parser.parseFromString(text, 'text/xml'); - // Get Link[template] - const link = xmlDoc.getElementsByTagName('Link')[0]; - const template = link.getAttribute('template'); - const url = URL.parse(template); - const { host } = url; // host includes the port - if (instanceURL !== host) { - console.log(`💫 ${instanceURL} -> ${host}`); - instanceURL = host; + if (!isWebDomain) { + try { + const res = await fetch( + `https://${instanceURL}/.well-known/host-meta`, + ); // returns XML + const text = await res.text(); + // Parse XML + const parser = new DOMParser(); + const xmlDoc = parser.parseFromString(text, 'text/xml'); + // Get Link[template] + const link = xmlDoc.getElementsByTagName('Link')[0]; + const template = link.getAttribute('template'); + const url = URL.parse(template); + const { host } = url; // host includes the port + if (instanceURL !== host) { + console.log(`💫 ${instanceURL} -> ${host}`); + instanceURL = host; + } + } catch (e) { + // Silently fail + console.error(e); } - } catch (e) { - // Silently fail - console.error(e); } store.local.set('instanceURL', instanceURL); @@ -257,6 +263,18 @@ function Login() { : t`Continue`} {' '} +
+ +