2022-02-14 10:57:57 +01:00
|
|
|
import { withSentry } from '@sentry/nextjs'
|
2021-12-27 15:59:32 +01:00
|
|
|
import prisma from 'libs/prisma'
|
|
|
|
import { NextApiRequest, NextApiResponse } from 'next'
|
2022-03-04 17:21:01 +01:00
|
|
|
import { getAuthenticatedUser } from 'services/api/utils'
|
|
|
|
import { methodNotAllowed, notAuthenticated } from 'utils'
|
2021-12-27 15:59:32 +01:00
|
|
|
|
|
|
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
2022-03-04 17:21:01 +01:00
|
|
|
const user = await getAuthenticatedUser(req)
|
|
|
|
if (!user) return notAuthenticated(res)
|
2021-12-27 15:59:32 +01:00
|
|
|
|
2022-06-03 13:20:19 +02:00
|
|
|
if (req.method === 'DELETE') {
|
|
|
|
const id = req.query.tokenId.toString()
|
|
|
|
const apiToken = await prisma.apiToken.delete({
|
2021-12-27 15:59:32 +01:00
|
|
|
where: { id },
|
|
|
|
})
|
2022-06-03 13:20:19 +02:00
|
|
|
return res.send({ apiToken })
|
2021-12-27 15:59:32 +01:00
|
|
|
}
|
2022-06-03 13:20:19 +02:00
|
|
|
methodNotAllowed(res)
|
2021-12-27 15:59:32 +01:00
|
|
|
}
|
|
|
|
|
2022-02-14 10:57:57 +01:00
|
|
|
export default withSentry(handler)
|