many breaking changes/fixes
This commit is contained in:
@@ -35,6 +35,8 @@ export const authOptions: AuthOptions = {
|
||||
passwordMatches = bcrypt.compareSync(password, findUser.password);
|
||||
}
|
||||
|
||||
console.log(passwordMatches);
|
||||
|
||||
if (passwordMatches) {
|
||||
return {
|
||||
id: findUser?.id,
|
||||
|
||||
@@ -4,21 +4,25 @@ import { authOptions } from "pages/api/auth/[...nextauth]";
|
||||
import getCollections from "@/lib/api/controllers/collections/getCollections";
|
||||
import postCollection from "@/lib/api/controllers/collections/postCollection";
|
||||
|
||||
type Data = {
|
||||
response: object[] | string;
|
||||
};
|
||||
|
||||
export default async function (
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<Data>
|
||||
) {
|
||||
export default async function (req: NextApiRequest, res: NextApiResponse) {
|
||||
const session = await getServerSession(req, res, authOptions);
|
||||
|
||||
if (!session?.user?.email) {
|
||||
return res.status(401).json({ response: "You must be logged in." });
|
||||
}
|
||||
|
||||
if (req.method === "GET") return await getCollections(req, res, session);
|
||||
|
||||
if (req.method === "POST") return await postCollection(req, res, session);
|
||||
if (req.method === "GET") {
|
||||
const collections = await getCollections(session.user.id);
|
||||
return res
|
||||
.status(collections.status)
|
||||
.json({ response: collections.response });
|
||||
} else if (req.method === "POST") {
|
||||
const newCollection = await postCollection(
|
||||
req.body.collectionName.trim(),
|
||||
session.user.id
|
||||
);
|
||||
return res
|
||||
.status(newCollection.status)
|
||||
.json({ response: newCollection.response });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,21 +5,25 @@ import getLinks from "@/lib/api/controllers/links/getLinks";
|
||||
import postLink from "@/lib/api/controllers/links/postLink";
|
||||
import deleteLink from "@/lib/api/controllers/links/deleteLink";
|
||||
|
||||
type Data = {
|
||||
response: object[] | string;
|
||||
};
|
||||
|
||||
export default async function (
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<Data>
|
||||
) {
|
||||
export default async function (req: NextApiRequest, res: NextApiResponse) {
|
||||
const session = await getServerSession(req, res, authOptions);
|
||||
|
||||
if (!session?.user?.email) {
|
||||
return res.status(401).json({ response: "You must be logged in." });
|
||||
}
|
||||
|
||||
if (req.method === "GET") return await getLinks(req, res, session);
|
||||
else if (req.method === "POST") return await postLink(req, res, session);
|
||||
else if (req.method === "DELETE") return await deleteLink(req, res, session);
|
||||
if (req.method === "GET") {
|
||||
const links = await getLinks(session.user.id);
|
||||
return res.status(links.status).json({ response: links.response });
|
||||
} else if (req.method === "POST") {
|
||||
const newlink = await postLink(req.body, session.user.id);
|
||||
return res.status(newlink.status).json({
|
||||
response: newlink.response,
|
||||
});
|
||||
} else if (req.method === "DELETE") {
|
||||
const deleted = await deleteLink(req.body, session.user.id);
|
||||
return res.status(deleted.status).json({
|
||||
response: deleted.response,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,5 +17,8 @@ export default async function (
|
||||
return res.status(401).json({ response: "You must be logged in." });
|
||||
}
|
||||
|
||||
if (req.method === "GET") return await getTags(req, res, session);
|
||||
if (req.method === "GET") {
|
||||
const tags = await getTags(session.user.id);
|
||||
return res.status(tags.status).json({ response: tags.response });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user