async function finalizeLink() { const urlParams = new URLSearchParams(window.location.search); const code = urlParams.get('code'); const state = urlParams.get('state'); const statusDiv = document.getElementById('status'); if (!code || !state) { statusDiv.innerHTML = "

Error: Missing data from Twitter

"; return; } try { const response = await fetch(`/api/v1/me/twitter/confirm?state=${state}&code=${code}`, { method: 'GET', }); const data = await response.json(); if (response.ok) { statusDiv.innerHTML = `

Success!

Linked as @${data.handle}

Redirecting you back...

`; setTimeout(() => { window.location.href = '/'; }, 2000); } else { statusDiv.innerHTML = `

Error: ${data.detail || 'Failed to link'}

`; } } catch (err) { statusDiv.innerHTML = "

Failed to connect to backend

"; } } finalizeLink();