More comments to clear my confused brain
This commit is contained in:
parent
632031d453
commit
c7f34c3621
17
js/auth.js
17
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(){
|
async function sendHome(){
|
||||||
await delay(2000);
|
await delay(2000);
|
||||||
@ -11,9 +18,9 @@ async function cmdOut(message) {
|
|||||||
cmd.insertAdjacentHTML("beforeend", html)
|
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`;
|
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",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"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");
|
cmdOut("Reading registration key");
|
||||||
const key = await getQuery("key");
|
const key = await getQuery("key");
|
||||||
cmdOut(`Key: ${key}`)
|
cmdOut(`Key: ${key}`)
|
||||||
|
Reference in New Issue
Block a user