Spaces:
Runtime error
Runtime error
File size: 1,520 Bytes
ae5391f b821729 ae5391f b821729 ae5391f b821729 ae5391f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
// show the loading animation when the login form is submitted
const loginBox = document.querySelector(".login-box");
const loginForm = document.querySelector(".login-form");
const tokenInput = document.getElementById("accessToken");
const loadingContainer = document.querySelector(".loading-container");
// some animations for validating token
// and initializing index
loginForm.addEventListener("submit", async (event) => {
event.preventDefault();
const token = tokenInput.value;
if (!token) return;
loadingContainer.classList.add("show"); // to show the loading animation
const loginResponse = await fetch(`/login?token=${token}`, {
method: "POST",
});
const loginData = await loginResponse.json();
if ("redirect" in loginData) {
// if the login response contains a "redirect" property, it means the login was successful
const initLlamaRep = await fetch(`initLlamaIndex?token=${token}`, {
method: "POST",
});
const initLangOpenRep = await fetch(`initLangOpen?token=${token}`, {
method: "POST",
});
const initLlamaData = await initLlamaRep.json();
const initLangOpenData = await initLangOpenRep.json();
if ("success" in initLlamaData || "success" in initLangOpenData) {
window.location.href = loginData.redirect;
}
} else if ("error" in loginData) {
// display error message login page
loadingContainer.classList.remove("show");
}
});
|