2023-02-24 11:32:28 -06:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
import { getServerSession } from "next-auth/next";
|
|
|
|
import { authOptions } from "pages/api/auth/[...nextauth]";
|
2023-03-05 15:03:20 -06:00
|
|
|
import getLinks from "@/lib/api/controllers/links/getLinks";
|
2023-02-24 11:32:28 -06:00
|
|
|
import postLink from "@/lib/api/controllers/links/postLink";
|
|
|
|
|
|
|
|
type Data = {
|
|
|
|
response: object[] | string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default async function (
|
|
|
|
req: NextApiRequest,
|
|
|
|
res: NextApiResponse<Data>
|
|
|
|
) {
|
|
|
|
const session = await getServerSession(req, res, authOptions);
|
|
|
|
|
|
|
|
if (!session?.user?.email) {
|
|
|
|
return res.status(401).json({ response: "You must be logged in." });
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if user is unauthorized to the collection (If isn't owner or doesn't has the required permission...)
|
|
|
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
2023-03-05 15:03:20 -06:00
|
|
|
if (req.method === "GET") return await getLinks(req, res, session);
|
2023-02-24 11:32:28 -06:00
|
|
|
if (req.method === "POST") return await postLink(req, res, session);
|
|
|
|
}
|