code refactoring + many security/bug fixes
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import archive from "@/lib/api/archive";
|
||||
import { prisma } from "@/lib/api/db";
|
||||
import authenticateUser from "@/lib/api/authenticateUser";
|
||||
import verifyUser from "@/lib/api/verifyUser";
|
||||
|
||||
const RE_ARCHIVE_LIMIT = Number(process.env.RE_ARCHIVE_LIMIT) || 5;
|
||||
|
||||
export default async function links(req: NextApiRequest, res: NextApiResponse) {
|
||||
const user = await authenticateUser({ req, res });
|
||||
if (!user) return res.status(404).json({ response: "User not found." });
|
||||
const user = await verifyUser({ req, res });
|
||||
if (!user) return;
|
||||
|
||||
const link = await prisma.link.findUnique({
|
||||
where: {
|
||||
|
||||
@@ -2,11 +2,11 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import deleteLinkById from "@/lib/api/controllers/links/linkId/deleteLinkById";
|
||||
import updateLinkById from "@/lib/api/controllers/links/linkId/updateLinkById";
|
||||
import getLinkById from "@/lib/api/controllers/links/linkId/getLinkById";
|
||||
import authenticateUser from "@/lib/api/authenticateUser";
|
||||
import verifyUser from "@/lib/api/verifyUser";
|
||||
|
||||
export default async function links(req: NextApiRequest, res: NextApiResponse) {
|
||||
const user = await authenticateUser({ req, res });
|
||||
if (!user) return res.status(404).json({ response: "User not found." });
|
||||
const user = await verifyUser({ req, res });
|
||||
if (!user) return;
|
||||
|
||||
if (req.method === "GET") {
|
||||
const updated = await getLinkById(user.id, Number(req.query.id));
|
||||
|
||||
@@ -2,11 +2,11 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import getLinks from "@/lib/api/controllers/links/getLinks";
|
||||
import postLink from "@/lib/api/controllers/links/postLink";
|
||||
import { LinkRequestQuery } from "@/types/global";
|
||||
import authenticateUser from "@/lib/api/authenticateUser";
|
||||
import verifyUser from "@/lib/api/verifyUser";
|
||||
|
||||
export default async function links(req: NextApiRequest, res: NextApiResponse) {
|
||||
const user = await authenticateUser({ req, res });
|
||||
if (!user) return res.status(404).json({ response: "User not found." });
|
||||
const user = await verifyUser({ req, res });
|
||||
if (!user) return;
|
||||
|
||||
if (req.method === "GET") {
|
||||
// Convert the type of the request query to "LinkRequestQuery"
|
||||
|
||||
Reference in New Issue
Block a user