CensoredManager/assets/js/auth.js
mctaylors 5f64caf6bc
Initial commit
Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
2024-06-06 22:39:59 +05:00

22 lines
No EOL
915 B
JavaScript

const notificationElement = document.getElementById("notification");
const apiProviderElement = document.getElementById("api-provider");
window.addEventListener("load", function () {
apiProviderElement.href = `https://${api_provider}`;
apiProviderElement.innerText = api_provider;
if (docCookies.hasItem('token')) {
document.getElementById('form').innerHTML = 'Already logged in! <a href="/"><button>Home</button></a>';
}
});
document.getElementById("token-form").addEventListener("submit", async (e) => {
e.preventDefault();
const token = document.getElementById("token").value;
if (await getId(token).then(value => value['status'])) {
docCookies.setItem("token", document.getElementById("token").value);
window.location = "/";
} else {
notificationElement.innerText = "Incorrect token!";
notificationElement.style.color = "red";
}
});