const statusNode = document.querySelector("#bootstrap-status");
const token = new URLSearchParams(location.hash.slice(1)).get("bootstrap");
const requestedReturnTo = new URLSearchParams(location.search).get("returnTo") || "";
const returnTo = requestedReturnTo.startsWith("/") && !requestedReturnTo.startsWith("//")
? requestedReturnTo
: "";
async function exchangeBootstrapToken() {
if (!token) {
statusNode.textContent = "Open the private link printed by typeduck-codex-web.";
return;
}
history.replaceState({}, "", "/");
const response = await fetch("/auth/exchange", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ token }),
});
if (!response.ok) {
statusNode.textContent = "This private link is invalid or has been replaced.";
return;
}
const result = await response.json();
location.replace(result.basePath + returnTo);
}
void exchangeBootstrapToken();