calcom/pages/api/integrations.ts
Alex Johansson a0a0ec86f0
add type-safe getSession() (#486)
* fix types for auth
* implement safer to use `getSession`
2021-08-18 11:52:25 +00:00

39 lines
No EOL
1.1 KiB
TypeScript

import prisma from "../../lib/prisma";
import { getSession } from "@lib/auth";
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: {
userId: session.user.id,
},
select: {
type: true,
key: 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; }
const id = req.body.id;
const deleteIntegration = await prisma.credential.delete({
where: {
id: id,
},
});
res.status(200).json({message: 'Integration deleted successfully'});
}
}