Debugging

This commit is contained in:
Fred Boniface 2023-04-07 21:15:33 +01:00
parent 14752b4f42
commit 7fbe592529
3 changed files with 14 additions and 15 deletions

View File

@ -19,21 +19,19 @@ async function cmdOut(message) {
} }
async function registerKey(key) { // Posts key to server and listens for response. async function registerKey(key) { // Posts key to server and listens for response.
var url = `${window.location.origin}/api/v1/register/register`; const url = `${window.location.origin}/api/v1/register/register`;
let res = await fetch(url, { // The response will contain the UUID which will be registered const res = await fetch(url, { // The response will contain the UUID which will be registered
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json" "Content-Type": "application/json"
}, },
redirect: "follow", redirect: "follow",
body: JSON.stringify(key) body: JSON.stringify({uuid: key})
}) })
if (res.JSON['result'] == "ok"){ const data = await res.json();
localStorage.setItem("uuid", res.JSON['uuid']); return res.status === 201
return true; ? (localStorage.setItem("uuid", data.uuid), true)
} else { : false;
return false;
}
} }
async function checkAuth(key) { async function checkAuth(key) {
@ -53,10 +51,12 @@ async function init(){ // Reads registration key from query, and calls registerK
const key = await getQuery("key"); const key = await getQuery("key");
cmdOut(`Temporary: ${key}`) cmdOut(`Temporary: ${key}`)
cmdOut("Requesting API Key from server"); cmdOut("Requesting API Key from server");
let res = await registerKey(key); if (!await registerKey(key)) {
console.log(JSON.stringify(res)) cmdOut("Failed to register key")
cmdOut("Checking key validity") hideLoading()
checkAuth(localStorage.getItem("uuid")) return
}
await checkAuth(localStorage.getItem("uuid"))
? cmdOut("Authentication succesful") ? cmdOut("Authentication succesful")
: cmdOut("Authentication failed") : cmdOut("Authentication failed")
} }

View File

@ -9,7 +9,6 @@ if ("serviceWorker" in navigator) {
async function pageInit() { async function pageInit() {
await loadQuickLinks(); await loadQuickLinks();
hideLoading(); // From lib.main hideLoading(); // From lib.main
localStorage.setItem("ver-web", document.getElementById('ver_str').textContent)
} }
async function gotoBoard(station){ async function gotoBoard(station){

View File

@ -78,7 +78,7 @@ async function register() { // Registers a device by sending POST request to API
if (! await isRegistered()) { if (! await isRegistered()) {
showLoading() showLoading()
let url = `${window.location.origin}/api/v1/register/request`; let url = `${window.location.origin}/api/v1/register/request`;
let email = document.getElementById("eml").textContent let email = document.getElementById("eml").value
let res = await fetch(url, { let res = await fetch(url, {
method: "POST", method: "POST",
headers: { headers: {