diff --git a/static/js/aeskeyshare.js b/static/js/aeskeyshare.js index 09d2d97..0fb0118 100644 --- a/static/js/aeskeyshare.js +++ b/static/js/aeskeyshare.js @@ -1,24 +1,17 @@ +// Add an event listener to handle incoming messages window.addEventListener("message", function(event) { - try { - let data = JSON.parse(event.data); - const access_token = data["access_token"]; - const redirect_uri = data["redirect_uri"]; + const access_token = event.data; - fetch("https://auth.hectabit.org/api/isloggedin", { - method: "POST", - body: JSON.stringify({ - access_token: access_token - }) + fetch("https://auth.hectabit.org/api/isloggedin", { + method: "POST", + body: JSON.stringify({ + access_token: access_token }) - .then((response) => { - if (response.status === 200) { - console.log("Key is valid"); - let newtab = window.open(redirect_uri); - newtab.postMessage(localStorage.getItem("DONOTSHARE-password"), "*"); - window.close(); - } - }); - } catch { - console.log("Error parsing JSON"); - } -}); + }) + .then((response) => function () { + if (response.status === 200) { + console.log("Key is valid") + window.postMessage(localStorage.getItem("DONOTSHARE-password"), event.origin) + } + }) +}); \ No newline at end of file diff --git a/templates/aeskeyshare.html b/templates/aeskeyshare.html index 39ceda8..c4f6f2d 100644 --- a/templates/aeskeyshare.html +++ b/templates/aeskeyshare.html @@ -7,5 +7,5 @@ -

Redirecting...

+

Sending key...