forked from spacebar/SplatNet
Feat: implement callback for TwitterAPI linking
This commit is contained in:
parent
7b586bbd5e
commit
67933ec76a
3 changed files with 76 additions and 0 deletions
37
callback/twitter.js
Normal file
37
callback/twitter.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
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 = "<h2>Error: Missing data from Twitter</h2>";
|
||||
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 = `
|
||||
<h2>Success!</h2>
|
||||
<p>Linked as @${data.handle}</p>
|
||||
<p>Redirecting you back...</p>
|
||||
`;
|
||||
setTimeout(() => {
|
||||
window.location.href = '/';
|
||||
}, 2000);
|
||||
} else {
|
||||
statusDiv.innerHTML = `<h2>Error: ${data.detail || 'Failed to link'}</h2>`;
|
||||
}
|
||||
} catch (err) {
|
||||
statusDiv.innerHTML = "<h2>Failed to connect to backend</h2>";
|
||||
}
|
||||
}
|
||||
|
||||
finalizeLink();
|
||||
Loading…
Reference in a new issue