npubbing works

This commit is contained in:
counterweight 2025-02-08 01:14:01 +01:00
parent b1ef0821de
commit bb7721f839
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
4 changed files with 104 additions and 0 deletions

View file

@ -12,6 +12,50 @@
<p>Now this is some production grade stuff, baby!</p>
<p>Your session's UUID: <%= uuid %>
</p>
<p id="pubkey-p" style="display:none">And your pubkey is: <span id="pubkey-span"></span></p>
</body>
<script>
window.onload = function () {
setTimeout(function () {
console.log("This code runs 2 seconds after the window has loaded.");
const npub = window.nostr.getPublicKey();
let pubkeyP = document.querySelector("#pubkey-p");
let pubkeySpan = document.querySelector("#pubkey-span");
npub.then(async function (npub) {
console.log(npub);
pubkeyP.style.display = "block";
pubkeySpan.innerText = npub;
try {
const response = await fetch('/api/session-npubbed', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
"npub": npub
})
});
if (response.ok) {
const data = await response.json();
console.log('SessionNpubbed record created successfully:', data);
} else {
const error = await response.json();
console.error('Failed to create sessionNpubbed record:', error);
}
} catch (error) {
console.error('An error occurred:', error);
}
}
)
}, 2000);
}
</script>
</html>