Ensure all the API routes reject banned users

This commit is contained in:
Keith Stevens
2023-01-10 19:16:13 +09:00
parent 600f7f7381
commit d94cb4b2d6
13 changed files with 51 additions and 117 deletions
+3 -11
View File
@@ -1,5 +1,5 @@
import { Prisma } from "@prisma/client";
import { getToken } from "next-auth/jwt";
import { withoutRole } from "src/lib/auth";
import { oasstApiClient } from "src/lib/oasst_api_client";
import prisma from "src/lib/prismadb";
@@ -13,15 +13,7 @@ import prisma from "src/lib/prismadb";
* 4) Records the new task in our local database.
* 5) Returns the newly created task to the client.
*/
const handler = async (req, res) => {
const token = await getToken({ req });
// Return nothing if the user isn't registered.
if (!token) {
res.status(401).end();
return;
}
const handler = withoutRole("banned", async (req, res, token) => {
// Parse out the local task ID and the interaction contents.
const { id: frontendId, content, update_type } = await JSON.parse(req.body);
@@ -65,6 +57,6 @@ const handler = async (req, res) => {
// Send the next task in the sequence to the client.
res.status(200).json(newRegisteredTask);
};
});
export default handler;