2021-03-24 15:03:04 +00:00
|
|
|
import prisma from '../../lib/prisma';
|
|
|
|
import { getSession } from 'next-auth/client';
|
|
|
|
|
|
|
|
export default async function handler(req, res) {
|
|
|
|
if (req.method === 'GET') {
|
|
|
|
// Check that user is authenticated
|
|
|
|
const session = await getSession({req: req});
|
|
|
|
|
|
|
|
if (!session) { res.status(401).json({message: 'You must be logged in to do this'}); return; }
|
|
|
|
|
|
|
|
const credentials = await prisma.credential.findMany({
|
|
|
|
where: {
|
2021-05-11 09:21:05 +00:00
|
|
|
userId: session.user.id,
|
2021-03-24 15:03:04 +00:00
|
|
|
},
|
|
|
|
select: {
|
2021-03-26 15:51:19 +00:00
|
|
|
type: true,
|
|
|
|
key: true
|
2021-03-24 15:03:04 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
res.status(200).json(credentials);
|
|
|
|
}
|
2021-04-10 12:02:35 +00:00
|
|
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
const id = req.body.id;
|
|
|
|
|
|
|
|
const deleteIntegration = await prisma.credential.delete({
|
|
|
|
where: {
|
|
|
|
id: id,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
res.status(200).json({message: 'Integration deleted successfully'});
|
|
|
|
}
|
2021-03-24 15:03:04 +00:00
|
|
|
}
|