A fault with our bandwidth provider is causing intermittent connectivity. Apologies for any inconvenience.
-
Customise your quick links on the Settings page.
diff --git a/js/auth.js b/js/auth.js
index 096722b..6e5608c 100644
--- a/js/auth.js
+++ b/js/auth.js
@@ -36,11 +36,27 @@ async function registerKey(key) { // Posts key to server and listens for respons
}
}
+async function checkAuth(key) {
+ const url = `${window.location.origin}/api/v1/auth/test`;
+ const res = await fetch(url, {
+ method: "GET",
+ redirect: "follow",
+ headers: {
+ "uuid": key
+ }
+ })
+ return res.status === 200 ? true : false
+}
+
async function init(){ // Reads registration key from query, and calls registerKey(key)
cmdOut("Reading registration key");
const key = await getQuery("key");
- cmdOut(`Key: ${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"))
+ ? cmdOut("Authentication succesful")
+ : cmdOut("Authentication failed")
}
\ No newline at end of file
diff --git a/js/settings.js b/js/settings.js
index cb23981..4410112 100644
--- a/js/settings.js
+++ b/js/settings.js
@@ -66,6 +66,7 @@ async function isRegistered() { // Check if a device is registered, returns BOOL
if (localStorage.getItem("uuid")) {
return true
// Also need an API Call here to check if auth is working.
+ // A Suitable function exists in auth.js - move it to lib.main.js
}
localStorage.removeItem("uuid");
return false
@@ -86,12 +87,10 @@ async function register() { // Registers a device by sending POST request to API
})
if (res.status == 201) {
showDone();
+ hideLoading();
+ return;
}
- // Need to send a post request to server with the email address
- // the server responds with a 201 or a 401 response.
- // Then the done popup can appear with a message asking the user
- // to check their emails for the link. The link takes then to the
- // auth page which has login in auth.js
+ log(`settings.register: Error: Fetch returned: ${res.status}`, "err")
} else {
logout()
}