inviting npubs
This commit is contained in:
parent
9c90b75bc0
commit
56121342d6
6 changed files with 76 additions and 2 deletions
|
|
@ -4,7 +4,7 @@ const path = require('path');
|
|||
|
||||
const sequelize = require('./database');
|
||||
const Session = require('./models/Session');
|
||||
const AppInvite = require('./models/AppInvite');
|
||||
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
|
|
|||
28
src/models/InvitedNpub.js
Normal file
28
src/models/InvitedNpub.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../database');
|
||||
|
||||
const InvitedNpub = sequelize.define('InvitedNpub', {
|
||||
uuid: {
|
||||
type: DataTypes.UUID,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
primaryKey: true
|
||||
},
|
||||
app_invite_uuid: {
|
||||
type: DataTypes.UUID,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
},
|
||||
invited_npub: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
created_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
tableName: 'invited_npub'
|
||||
});
|
||||
|
||||
module.exports = InvitedNpub;
|
||||
28
src/public/javascript/invite.js
Normal file
28
src/public/javascript/invite.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
function acceptInvite() {
|
||||
const npub = window.nostr.getPublicKey();
|
||||
console.log("Npub is" + npub);
|
||||
|
||||
npub.then(async function (npub) {
|
||||
try {
|
||||
const response = await fetch('/api/invited-npub', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
"npub": npub
|
||||
})
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('An error occurred:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ const express = require('express');
|
|||
const uuid = require("uuid");
|
||||
|
||||
const SessionNpubbed = require('../models/SessionNpubbed');
|
||||
const InvitedNpub = require('../models/InvitedNpub');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
|
|
@ -41,4 +42,18 @@ router.post('/session-npubbed', async (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
router.post('/invited-npub', async (req, res) => {
|
||||
const sessionUuid = req.cookies.sessionUuid;
|
||||
const npub = req.body.npub;
|
||||
|
||||
await InvitedNpub.create({
|
||||
uuid: uuid.v7(),
|
||||
app_invite_uuid: uuid.v7(), //should read from cookie instead
|
||||
invited_npub: npub,
|
||||
created_at: new Date().toISOString()
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ const router = express.Router();
|
|||
|
||||
const AppInvite = require('../models/AppInvite');
|
||||
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
res.render('index', { uuid: req.cookies.sessionUuid });
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,12 +5,16 @@
|
|||
<title>Invite Details</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<script src="/javascript/invite.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Invite Details</h1>
|
||||
<p>Invite UUID: <%= invite.uuid %>
|
||||
</p>
|
||||
<form>
|
||||
<button onclick="acceptInvite()">Click to accept invite with Nostr</button>
|
||||
</form>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue