Auth improvements

This commit is contained in:
Laura Hausmann 2023-10-09 19:31:31 +02:00
parent 5255fdd31c
commit 81844e476c
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -20,15 +20,14 @@ async function auth() {
const instance = document.getElementById('instance').value; const instance = document.getElementById('instance').value;
const domain = instance.match(/(?:https?:\/\/)?(.*)/)[1]; const domain = instance.match(/(?:https?:\/\/)?(.*)/)[1];
if (!domain) { if (!domain) {
document.getElementById('message').textContent = 'Invalid instance'; setMessage('Invalid instance', false);
return; return;
} }
localStorage.setItem('domain', domain); localStorage.setItem('domain', domain);
if (!localStorage.getItem(`client_id_${domain}`) || !localStorage.getItem(`client_secret_${domain}`)) { // We need to run this every time in cases like Iceshrimp, where the client id/secret aren't reusable (yet) because they contain use-once session information
await registerApp(domain); await registerApp(domain);
}
authorize(domain); authorize(domain);
} }
@ -182,7 +181,7 @@ async function setStateAndRedirect(access_token, domain) {
window.location.href = '/'; window.location.href = '/';
} }
function setMessage(message) { function setMessage(message, disabled = true) {
document.getElementById('message').textContent = message; document.getElementById('message').textContent = message;
document.getElementById('btn').disabled = true; document.getElementById('btn').disabled = disabled;
} }