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,8 +1,6 @@
// 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",
@ -10,15 +8,10 @@ window.addEventListener("message", function(event) {
access_token: access_token access_token: access_token
}) })
}) })
.then((response) => { .then((response) => function () {
if (response.status === 200) { if (response.status === 200) {
console.log("Key is valid"); console.log("Key is valid")
let newtab = window.open(redirect_uri); window.postMessage(localStorage.getItem("DONOTSHARE-password"), event.origin)
newtab.postMessage(localStorage.getItem("DONOTSHARE-password"), "*");
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>