25 lines
791 B
TypeScript
25 lines
791 B
TypeScript
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||
|
import { getServerSession } from "next-auth/next";
|
||
|
import { authOptions } from "pages/api/auth/[...nextauth]";
|
||
|
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...)
|
||
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||
|
|
||
|
if (req.method === "POST") return await postLink(req, res, session);
|
||
|
}
|