2021-08-18 11:52:25 +00:00
|
|
|
import { getSession } from "@lib/auth";
|
2021-03-24 15:03:04 +00:00
|
|
|
|
2021-09-22 19:52:38 +00:00
|
|
|
import prisma from "../../lib/prisma";
|
|
|
|
|
2021-03-24 15:03:04 +00:00
|
|
|
export default async function handler(req, res) {
|
2021-08-19 12:27:01 +00:00
|
|
|
if (req.method === "GET") {
|
|
|
|
// Check that user is authenticated
|
|
|
|
const session = await getSession({ req: req });
|
2021-04-10 12:02:35 +00:00
|
|
|
|
2021-08-19 12:27:01 +00:00
|
|
|
if (!session) {
|
|
|
|
res.status(401).json({ message: "You must be logged in to do this" });
|
|
|
|
return;
|
|
|
|
}
|
2021-04-10 12:02:35 +00:00
|
|
|
|
2021-08-19 12:27:01 +00:00
|
|
|
const credentials = await prisma.credential.findMany({
|
|
|
|
where: {
|
|
|
|
userId: session.user.id,
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
type: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
res.status(200).json(credentials);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req.method == "DELETE") {
|
|
|
|
const session = await getSession({ req: req });
|
|
|
|
|
|
|
|
if (!session) {
|
|
|
|
res.status(401).json({ message: "You must be logged in to do this" });
|
|
|
|
return;
|
|
|
|
}
|
2021-04-10 12:02:35 +00:00
|
|
|
|
2021-08-19 12:27:01 +00:00
|
|
|
const id = req.body.id;
|
2021-04-10 12:02:35 +00:00
|
|
|
|
2021-08-19 12:27:01 +00:00
|
|
|
await prisma.credential.delete({
|
|
|
|
where: {
|
|
|
|
id: id,
|
|
|
|
},
|
|
|
|
});
|
2021-04-10 12:02:35 +00:00
|
|
|
|
2021-08-19 12:27:01 +00:00
|
|
|
res.status(200).json({ message: "Integration deleted successfully" });
|
|
|
|
}
|
|
|
|
}
|