diff --git a/js/auth.js b/js/auth.js index 91a85ea..4d26fb1 100644 --- a/js/auth.js +++ b/js/auth.js @@ -1,5 +1,12 @@ -const cmd = document.getElementById("cmd") -init(); +/* +Auth process: User Requests Key => Server emails key to user => + user opens link on auth.html => + website POSTs key to server => Server checks validity => + Server responds with the users auth key => + auth.js adds this to localStorage +*/ +const cmd = document.getElementById("cmd") // Assign element to const +init(); // Run init function async function sendHome(){ await delay(2000); @@ -11,9 +18,9 @@ async function cmdOut(message) { cmd.insertAdjacentHTML("beforeend", html) } -async function registerKey(key) { +async function registerKey(key) { // Posts key to server and listens for response. var url = `${window.location.origin}/api/v1/auth/register`; - let res = await fetch(url, { + let res = await fetch(url, { // The response will contain the UUID which will be registered method: "POST", headers: { "Content-Type": "application/json" @@ -28,7 +35,7 @@ async function registerKey(key) { } } -async function init(){ +async function init(){ // Reads registration key from query, and calls registerKey(key) cmdOut("Reading registration key"); const key = await getQuery("key"); cmdOut(`Key: ${key}`)