mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-03-14 12:18:30 +03:00
Handle WEB_DOMAIN for login
Turns out .well-known routes are CORS-enabled
This commit is contained in:
parent
463ec48a8d
commit
49c7ccb0cb
2 changed files with 35 additions and 12 deletions
22
src/locales/en.po
generated
22
src/locales/en.po
generated
|
@ -1345,7 +1345,7 @@ msgid "Accounts…"
|
|||
msgstr ""
|
||||
|
||||
#: src/components/nav-menu.jsx:363
|
||||
#: src/pages/login.jsx:166
|
||||
#: src/pages/login.jsx:189
|
||||
#: src/pages/status.jsx:792
|
||||
#: src/pages/welcome.jsx:64
|
||||
msgid "Log in"
|
||||
|
@ -1740,7 +1740,7 @@ msgstr ""
|
|||
#: src/components/shortcuts-settings.jsx:75
|
||||
#: src/components/shortcuts-settings.jsx:84
|
||||
#: src/components/shortcuts-settings.jsx:122
|
||||
#: src/pages/login.jsx:170
|
||||
#: src/pages/login.jsx:193
|
||||
msgid "Instance"
|
||||
msgstr ""
|
||||
|
||||
|
@ -2368,7 +2368,7 @@ msgstr "Login required."
|
|||
|
||||
#: src/compose.jsx:90
|
||||
#: src/pages/http-route.jsx:91
|
||||
#: src/pages/login.jsx:247
|
||||
#: src/pages/login.jsx:270
|
||||
msgid "Go home"
|
||||
msgstr ""
|
||||
|
||||
|
@ -3052,32 +3052,32 @@ msgstr ""
|
|||
msgid "No lists yet."
|
||||
msgstr ""
|
||||
|
||||
#: src/pages/login.jsx:86
|
||||
#: src/pages/login.jsx:99
|
||||
#: src/pages/login.jsx:109
|
||||
#: src/pages/login.jsx:122
|
||||
msgid "Failed to register application"
|
||||
msgstr "Failed to register application"
|
||||
|
||||
#: src/pages/login.jsx:185
|
||||
#: src/pages/login.jsx:208
|
||||
msgid "instance domain"
|
||||
msgstr "instance domain"
|
||||
|
||||
#: src/pages/login.jsx:209
|
||||
#: src/pages/login.jsx:232
|
||||
msgid "e.g. “mastodon.social”"
|
||||
msgstr ""
|
||||
|
||||
#: src/pages/login.jsx:220
|
||||
#: src/pages/login.jsx:243
|
||||
msgid "Failed to log in. Please try again or try another instance."
|
||||
msgstr ""
|
||||
|
||||
#: src/pages/login.jsx:232
|
||||
#: src/pages/login.jsx:255
|
||||
msgid "Continue with {selectedInstanceText}"
|
||||
msgstr ""
|
||||
|
||||
#: src/pages/login.jsx:233
|
||||
#: src/pages/login.jsx:256
|
||||
msgid "Continue"
|
||||
msgstr ""
|
||||
|
||||
#: src/pages/login.jsx:241
|
||||
#: src/pages/login.jsx:264
|
||||
msgid "Don't have an account? Create one!"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
@ -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 } =
|
||||
|
|
Loading…
Add table
Reference in a new issue