import { authenticate, setLimit } from "../../../libs/db"; export default function handler(req, res) { // put method if (req.method === "PUT") { const { token, limit } = req.body; // authenticate if (!authenticate(token)) { res.status(401).json({ error: "Unauthorized", }); return; } // check type is integer const limitInt = parseInt(limit); if (!limitInt) { res.status(400).json({ error: "limit must be integer", }); return; } setLimit(limitInt); res.status(200).send({ success: true }); } else { res.status(405).send({ error: "method not allowed" }); } }