Skip to content

Commit

Permalink
Handle WEB_DOMAIN for login
Browse files Browse the repository at this point in the history
Turns out .well-known routes are CORS-enabled
  • Loading branch information
cheeaun committed Sep 7, 2024
1 parent 463ec48 commit 49c7ccb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
22 changes: 11 additions & 11 deletions src/locales/en.po

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 24 additions & 1 deletion src/pages/login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,32 @@ function Login() {

const submitInstance = (instanceURL) => {
if (!instanceURL) return;
store.local.set('instanceURL', instanceURL);

(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;
}
} catch (e) {
// Silently fail
console.error(e);
}

store.local.set('instanceURL', instanceURL);

setUIState('loading');
try {
const { client_id, client_secret, vapid_key } =
Expand Down

0 comments on commit 49c7ccb

Please sign in to comment.