v0.9.4 bugs fixes
This commit is contained in:
@@ -70,12 +70,10 @@ router.post('/subscribe', authMiddleware, (req, res) => {
|
||||
return res.status(400).json({ error: 'Invalid subscription' });
|
||||
}
|
||||
const db = getDb();
|
||||
// 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);
|
||||
const device = req.device || 'desktop';
|
||||
// Delete any existing subscription for this user+device or this endpoint, then insert fresh
|
||||
db.prepare('DELETE FROM push_subscriptions WHERE endpoint = ? OR (user_id = ? AND device = ?)').run(endpoint, req.user.id, device);
|
||||
db.prepare('INSERT INTO push_subscriptions (user_id, device, endpoint, p256dh, auth) VALUES (?, ?, ?, ?, ?)').run(req.user.id, device, endpoint, keys.p256dh, keys.auth);
|
||||
res.json({ success: true });
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user