fix: move 401 to throw early in all endpoints
This commit is contained in:
1 parent
307eddcbd5
commit
8d5605dc7b
13 files changed
+39
-27
No files matched your search
@@ -91,7 +91,8 @@ export async function userById(req: NextApiRequest, res: NextApiResponse<UserRes
|
||||
const safeBody = schemaUserBodyParams.safeParse(body);
|
||||
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
|
||||
const userId = req.userId;
|
||||
if (safeQuery.data.id === userId) {
|
||||
if (safeQuery.data.id !== userId) res.status(401).json({ message: "Unauthorized" });
|
||||
else {
|
||||
switch (method) {
|
||||
case "GET":
|
||||
await prisma.user
|
||||
@@ -132,7 +133,7 @@ export async function userById(req: NextApiRequest, res: NextApiResponse<UserRes
|
||||
res.status(405).json({ message: "Method not allowed" });
|
||||
break;
|
||||
}
|
||||
} else res.status(401).json({ message: "Unauthorized" });
|
||||
}
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_GET_DELETE_PATCH")(withValidQueryIdTransformParseInt(userById));
|
||||
Reference in new issue
Block a user