Spaces:
Running
Running
Update routes/push.js
Browse files8 unmodified lines91011121314158 unmodified linesif (token !== null && token !== '' && (typeof token !== 'string' || token.length > 500 || token.length < 10)) {return res.status(400).json({ error: 'Invalid token' });}await User.findOneAndUpdate({ username: req.user.username }, { pushToken: token || null });res.json({ success: true });} catch { res.status(500).send(''); }});8 unmodified lines91011121314151617181920212223248 unmodified linesif (token !== null && token !== '' && (typeof token !== 'string' || token.length > 500 || token.length < 10)) {return res.status(400).json({ error: 'Invalid token' });}const user = await User.findOne({ username: req.user.username });if (!user) return res.status(404).json({ error: 'Not found' });if (user.pushToken && user.pushToken !== token) {const { sendPushNotification } = require('../services/push');await sendPushNotification(req.user.username, {notification: { title: 'Push Token Changed', body: 'Your notification device was changed. If this was not you, check your account security.' }});}user.pushToken = token || null;await user.save();res.json({ success: true });} catch { res.status(500).send(''); }});
routes/push.js+10-1