worksss
This commit is contained in:
parent
768efaf3a2
commit
fb9832fabb
8 changed files with 306 additions and 92 deletions
|
|
@ -1,25 +1,40 @@
|
|||
async function acceptInvite() {
|
||||
const publicKey = await window.nostr.getPublicKey();
|
||||
|
||||
// check if there is nostr extension
|
||||
if (!window.nostr) {
|
||||
console.log("No Nostr extension found.");
|
||||
return { success: false, error: "No Nostr extension detected." };
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/sign-public-key-up', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
publicKey
|
||||
})
|
||||
const challengeResponse = await fetch("/api/signup/nostr-challenge");
|
||||
if (!challengeResponse.ok) throw new Error("Failed to fetch challenge");
|
||||
const { challenge } = await challengeResponse.json();
|
||||
|
||||
const pubkey = await window.nostr.getPublicKey();
|
||||
|
||||
const event = {
|
||||
kind: 22242,
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
tags: [["challenge", challenge]],
|
||||
content: "Sign this challenge to authenticate",
|
||||
pubkey: pubkey
|
||||
};
|
||||
|
||||
const signedEvent = await window.nostr.signEvent(event);
|
||||
|
||||
const verifyResponse = await fetch("/api/signup/nostr-verify", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(signedEvent),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
console.log('invited-npub record created successfully:', data);
|
||||
} else {
|
||||
const error = await response.json();
|
||||
console.error('Failed to create invited-npub record:', error);
|
||||
if (verifyResponse.status === 200) {
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('An error occurred:', error);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (error) { }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue