pis #2
20
js/auth.js
20
js/auth.js
@ -30,7 +30,7 @@ async function registerKey(key) { // Posts key to server and listens for respons
|
|||||||
})
|
})
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
return res.status === 201
|
return res.status === 201
|
||||||
? (localStorage.setItem("uuid", data.uuid), true)
|
? (localStorage.setItem("uuid", data.api_key), true)
|
||||||
: false;
|
: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,16 +47,24 @@ async function checkAuth(key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function init(){ // Reads registration key from query, and calls registerKey(key)
|
async function init(){ // Reads registration key from query, and calls registerKey(key)
|
||||||
cmdOut("Reading registration key");
|
cmdOut("Reading authorisation code");
|
||||||
const key = await getQuery("key");
|
const key = await getQuery("key");
|
||||||
cmdOut(`Temporary: ${key}`)
|
|
||||||
cmdOut("Requesting API Key from server");
|
cmdOut("Requesting API Key from server");
|
||||||
if (!await registerKey(key)) {
|
if (!await registerKey(key)) {
|
||||||
cmdOut("Failed to register key")
|
cmdOut("Failed to register key")
|
||||||
hideLoading()
|
hideLoading()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await checkAuth(localStorage.getItem("uuid"))
|
showLoading()
|
||||||
? cmdOut("Authentication succesful")
|
if (! await checkAuth(localStorage.getItem("uuid"))) {
|
||||||
: cmdOut("Authentication failed")
|
cmdOut("Authentication Check failed")
|
||||||
|
cmdOut("Please try again")
|
||||||
|
hideLoading()
|
||||||
|
await delay(2000)
|
||||||
|
location.replace("./")
|
||||||
|
}
|
||||||
|
hideLoading();
|
||||||
|
cmdOut("Authentication succesful")
|
||||||
|
await delay(2000)
|
||||||
|
location.replace("./")
|
||||||
}
|
}
|
@ -87,7 +87,7 @@ async function hideLoading() {
|
|||||||
/* DEPRECIATED: Alias for hideLoading() - Marked for removal*/
|
/* DEPRECIATED: Alias for hideLoading() - Marked for removal*/
|
||||||
async function clearLoading() {
|
async function clearLoading() {
|
||||||
log("Depreciated function called - clearLoading() - Alias to hideLoading()", "WARN")
|
log("Depreciated function called - clearLoading() - Alias to hideLoading()", "WARN")
|
||||||
await hideLoading();
|
hideLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function showLoading() {
|
async function showLoading() {
|
||||||
|
Reference in New Issue
Block a user