diff --git a/pages/api/auth/[...nextauth].js b/pages/api/auth/[...nextauth].js index bf45f94..47b97d5 100644 --- a/pages/api/auth/[...nextauth].js +++ b/pages/api/auth/[...nextauth].js @@ -1,6 +1,5 @@ import NextAuth from "next-auth"; import GoogleProvider from "next-auth/providers/google"; -import GithubProvider from "next-auth/providers/github"; import { MongoDBAdapter } from "@next-auth/mongodb-adapter" import clientPromise from "../../../lib/mongodb" diff --git a/pages/api/delete/[id].ts b/pages/api/delete/[id].ts index 3f06313..0663092 100644 --- a/pages/api/delete/[id].ts +++ b/pages/api/delete/[id].ts @@ -1,21 +1,28 @@ import type { NextApiRequest, NextApiResponse } from "next"; -import { connectToDatabase } from '../../../lib/mongodb-old' +import { connectToDatabase } from "../../../lib/mongodb-old"; import { getSession } from "next-auth/react"; import { ObjectID } from "mongodb"; export default async (req: NextApiRequest, res: NextApiResponse) => { - const { db } = await connectToDatabase() + const { db } = await connectToDatabase(); const session = await getSession({ req }); + + if (!req.query.id) { + return res.status(400).send("No ID provided"); + } + const id: string = req.query.id.toString(); if (session && session.user) { - try { - const posts = await db.collection('posts').deleteOne({ _id: ObjectID(id) }) - res.status(200).send(posts) - } catch (e) { - res.status(500).json(e) - } + try { + const posts = await db + .collection("posts") + .deleteOne({ _id: ObjectID(id) }); + res.status(200).send(posts); + } catch (e) { + res.status(500).json(e); + } } else { - res.send({ message: 'Not logged in' }) + res.send({ message: "Not logged in" }); } }; diff --git a/pages/api/post/[id].ts b/pages/api/post/[id].ts index cd11439..f7a32ce 100644 --- a/pages/api/post/[id].ts +++ b/pages/api/post/[id].ts @@ -4,6 +4,11 @@ import { ObjectId } from "bson"; export default async (req: NextApiRequest, res: NextApiResponse) => { const { db } = await connectToDatabase(); + + if (!req.query.id) { + return res.status(400).send("No ID provided"); + } + const id: string = req.query.id.toString(); const post = await db