v0.8.7 pin bug fixes

This commit is contained in:
2026-03-13 11:47:33 -04:00
parent 6d435844c9
commit 83b2105a9a
6 changed files with 45 additions and 39 deletions

View File

@@ -70,11 +70,12 @@ router.post('/subscribe', authMiddleware, (req, res) => {
return res.status(400).json({ error: 'Invalid subscription' });
}
const db = getDb();
db.prepare(`
INSERT INTO push_subscriptions (user_id, endpoint, p256dh, auth)
VALUES (?, ?, ?, ?)
ON CONFLICT(endpoint) DO UPDATE SET user_id = ?, p256dh = ?, auth = ?
`).run(req.user.id, endpoint, keys.p256dh, keys.auth, req.user.id, keys.p256dh, keys.auth);
// Use DELETE+INSERT to avoid relying on any specific UNIQUE constraint
// (existing DBs may have different schemas for this table)
const delStmt = db.prepare('DELETE FROM push_subscriptions WHERE endpoint = ?');
const insStmt = db.prepare('INSERT INTO push_subscriptions (user_id, endpoint, p256dh, auth) VALUES (?, ?, ?, ?)');
delStmt.run(endpoint);
insStmt.run(req.user.id, endpoint, keys.p256dh, keys.auth);
res.json({ success: true });
});