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

View File

@ -9,7 +9,6 @@ if ("serviceWorker" in navigator) {
async function pageInit() {
await loadQuickLinks();
hideLoading(); // From lib.main
localStorage.setItem("ver-web", document.getElementById('ver_str').textContent)
}
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()) {
showLoading()
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, {
method: "POST",
headers: {