npubbing works
This commit is contained in:
parent
b1ef0821de
commit
bb7721f839
4 changed files with 104 additions and 0 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -134,3 +134,6 @@ dist
|
|||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
|
||||
container-data/
|
||||
31
index.js
31
index.js
|
|
@ -4,6 +4,7 @@ const cookieParser = require('cookie-parser');
|
|||
|
||||
const sequelize = require('./database');
|
||||
const Session = require('./models/Session');
|
||||
const SessionNpubbed = require('./models/SessionNpubbed');
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
|
@ -18,6 +19,8 @@ sequelize.sync()
|
|||
|
||||
app.use(cookieParser());
|
||||
|
||||
app.use(express.json());
|
||||
|
||||
app.set('view engine', 'ejs');
|
||||
app.set('views', './views');
|
||||
|
||||
|
|
@ -37,6 +40,34 @@ app.get('/', (req, res) => {
|
|||
res.render('index', { uuid: req.cookies.sessionUuid });
|
||||
});
|
||||
|
||||
|
||||
app.post('/api/session-npubbed', async (req, res) => {
|
||||
console.log(req.body);
|
||||
const sessionUuid = req.cookies.sessionUuid;
|
||||
const npub = req.body.npub;
|
||||
|
||||
if (!sessionUuid || !npub) {
|
||||
return res.status(400).json({ error: 'Missing session_uuid or npub' });
|
||||
}
|
||||
|
||||
console.log("This is the npub: ${npub}");
|
||||
|
||||
try {
|
||||
await SessionNpubbed.create({
|
||||
sessionNpubbedUuid: uuid.v7(),
|
||||
sessionUuid: sessionUuid,
|
||||
npub: npub,
|
||||
created_at: new Date().toISOString()
|
||||
});
|
||||
|
||||
res.json({ message: 'SessionNpubbed record created successfully' });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error('Error creating sessionNpubbed record:', error);
|
||||
res.status(500).json({ error: 'Failed to create sessionNpubbed record' });
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Server started on port ${port}`);
|
||||
});
|
||||
|
|
|
|||
26
models/SessionNpubbed.js
Normal file
26
models/SessionNpubbed.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../database');
|
||||
|
||||
const SessionNpubbed = sequelize.define('SessionNpubbed', {
|
||||
sessionNpubbedUuid: {
|
||||
type: DataTypes.UUID,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
primaryKey: true
|
||||
},
|
||||
sessionUuid: {
|
||||
type: DataTypes.UUID,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
},
|
||||
npub: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
created_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = SessionNpubbed;
|
||||
|
|
@ -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>
|
||||
Loading…
Add table
Add a link
Reference in a new issue