check for invite being spent
This commit is contained in:
parent
61d2a4acd8
commit
a0fcba1abb
3 changed files with 48 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ const uuid = require("uuid");
|
|||
|
||||
const SessionNpubbed = require('../models/SessionNpubbed');
|
||||
const InvitedNpub = require('../models/InvitedNpub');
|
||||
const AppInvite = require('../models/AppInvite');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
|
|
@ -47,6 +48,22 @@ router.post('/invited-npub', async (req, res) => {
|
|||
const inviteUuid = req.cookies.inviteUuid;
|
||||
const npub = req.body.npub;
|
||||
|
||||
const invite = await AppInvite.findOne({ where: { uuid: inviteUuid } });
|
||||
|
||||
if (!invite) {
|
||||
return res.status(404).render('error', { message: 'Invite not found' });
|
||||
}
|
||||
|
||||
const isInviteSpent = await InvitedNpub.findOne({
|
||||
where: {
|
||||
app_invite_uuid: inviteUuid
|
||||
}
|
||||
})
|
||||
|
||||
if (isInviteSpent) {
|
||||
return res.render('invite_spent', { invite })
|
||||
}
|
||||
|
||||
await InvitedNpub.create({
|
||||
uuid: uuid.v7(),
|
||||
app_invite_uuid: inviteUuid,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ const express = require('express');
|
|||
const router = express.Router();
|
||||
|
||||
const AppInvite = require('../models/AppInvite');
|
||||
const InvitedNpub = require('../models/InvitedNpub');
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
res.render('index', { uuid: req.cookies.sessionUuid });
|
||||
|
|
@ -19,6 +20,16 @@ router.get('/invite/:inviteUuid', async (req, res) => {
|
|||
return res.status(404).render('error', { message: 'Invite not found' });
|
||||
}
|
||||
|
||||
const isInviteSpent = await InvitedNpub.findOne({
|
||||
where: {
|
||||
app_invite_uuid: inviteUuid
|
||||
}
|
||||
})
|
||||
|
||||
if (isInviteSpent) {
|
||||
return res.render('invite_spent', { invite })
|
||||
}
|
||||
|
||||
return res.render('invite', { invite });
|
||||
|
||||
} catch (error) {
|
||||
|
|
|
|||
20
src/views/invite_spent.ejs
Normal file
20
src/views/invite_spent.ejs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>Invite Details</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Invite Details</h1>
|
||||
<p>Invite UUID: <%= invite.uuid %>
|
||||
</p>
|
||||
<h2>Wait right there buddy... that invite has been spent already!</h2>
|
||||
<form>
|
||||
<button onclick="" disabled>Click to accept invite with Nostr</button>
|
||||
</form>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue