this repo has no description

support pds urls and ?target login

vielle.dev d3d9a94f cbc3962b

verified
+33 -13
+33 -13
src/pages/atproto/login.astro
··· 13 13 if (localStorage.getItem("did") && (await getAuth().then((x) => !!x[0]))) 14 14 window.location.assign("/"); 15 15 16 + const authorize = async (handle: string) => { 17 + const target = handle.startsWith("did:") 18 + ? (handle as `did:${string}:${string}`) 19 + : handle.startsWith("https://") 20 + ? (handle as `https://${string}`) 21 + : (handle as `${string}.${string}`); 22 + 23 + const authUrl = await createAuthorizationUrl({ 24 + target: !handle.startsWith("https://") 25 + ? { 26 + type: "account", 27 + identifier: target as 28 + | `did:${string}:${string}` 29 + | `${string}.${string}`, 30 + } 31 + : { 32 + type: "pds", 33 + serviceUrl: target, 34 + }, 35 + scope: metadata.scope, 36 + }).catch((err) => { 37 + alert(`Error: ${err}`); 38 + console.error(err); 39 + throw err; 40 + }); 41 + 42 + window.location.assign(authUrl); 43 + }; 44 + 16 45 const submit = document.getElementById( 17 46 "submit", 18 47 ) as HTMLButtonElement | null; ··· 28 57 const handle = unameEl.value; 29 58 submit.disabled = true; 30 59 31 - const authUrl = await createAuthorizationUrl({ 32 - target: { 33 - type: "account", 34 - identifier: handle as `${string}.${string}`, 35 - }, 36 - scope: metadata.scope, 37 - }).catch((err) => { 60 + await authorize(handle).catch(() => { 38 61 submit.disabled = false; 39 - alert(`Error: ${err}`); 40 - console.error(err); 41 - throw err; 42 62 }); 63 + }); 43 64 44 - await new Promise((res) => setTimeout(res, 200)); // let browser persist local storage 45 - window.location.assign(authUrl); 46 - }); 65 + const target = new URLSearchParams(window.location.search).get("target"); 66 + if (target) await authorize(target); 47 67 </script> 48 68 <style> 49 69 :global(html, body) {