Made aeskeyshare work properly

This commit is contained in:
Tracker-Friendly 2024-04-29 21:18:46 +01:00
parent 8299915502
commit 6e87268930
2 changed files with 15 additions and 22 deletions

View File

@ -1,24 +1,17 @@
// Add an event listener to handle incoming messages
window.addEventListener("message", function(event) { window.addEventListener("message", function(event) {
try { const access_token = event.data;
let data = JSON.parse(event.data);
const access_token = data["access_token"];
const redirect_uri = data["redirect_uri"];
fetch("https://auth.hectabit.org/api/isloggedin", { fetch("https://auth.hectabit.org/api/isloggedin", {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
access_token: access_token access_token: access_token
})
}) })
.then((response) => { })
if (response.status === 200) { .then((response) => function () {
console.log("Key is valid"); if (response.status === 200) {
let newtab = window.open(redirect_uri); console.log("Key is valid")
newtab.postMessage(localStorage.getItem("DONOTSHARE-password"), "*"); window.postMessage(localStorage.getItem("DONOTSHARE-password"), event.origin)
window.close(); }
} })
});
} catch {
console.log("Error parsing JSON");
}
}); });

View File

@ -7,5 +7,5 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="icon" href="/static/svg/favicon.svg"> <link rel="icon" href="/static/svg/favicon.svg">
</head> </head>
<p>Redirecting...</p> <p>Sending key...</p>
<script src="/static/js/aeskeyshare.js"></script> <script src="/static/js/aeskeyshare.js"></script>