diff --git a/front/static/dashboard.html b/front/static/dashboard.html index 299c8e0..6b2019c 100644 --- a/front/static/dashboard.html +++ b/front/static/dashboard.html @@ -1,38 +1,41 @@ - - - - - - - Reimbursinator - - - -
-

Reimbursinator Report

- + + + + + + + Reimbursinator + + + +
+
+

Reimbursinator Report

- + +
+ + diff --git a/front/static/logout.js b/front/static/logout.js new file mode 100644 index 0000000..181372e --- /dev/null +++ b/front/static/logout.js @@ -0,0 +1,33 @@ +function postToLogoutEndpoint(event) { + event.preventDefault(); + + const token = localStorage.getItem("token"); + const url = "https://reqres.in/api/logout" // mock api service + const xhr = new XMLHttpRequest(); + + xhr.open("POST", url, true); + xhr.setRequestHeader("Authorization", `Token ${token}`); + xhr.onreadystatechange = function() { + if (this.readyState === 4) { + if (this.status === 200) { + console.log("LOGOUT SUCCESS!"); + console.log(`Server response:\n${this.response}`); + localStorage.removeItem("token"); + window.location.replace("index.html"); + } else { + console.log("LOGOUT FAILURE!"); + console.log(`Server status: ${this.status}`); + console.log(`Server response:\n${this.response}`); + } + } + }; + + xhr.onerror = function() { + alert("Error connecting to authentication server!"); + }; + + xhr.send(); +} + +const logoutLink = document.querySelector("#logoutLink"); +logoutLink.addEventListener("click", postToLogoutEndpoint);