2
0
Files
bot/apps/builder/pages/api/users/[userId]/api-tokens/[tokenId].ts

22 lines
668 B
TypeScript
Raw Normal View History

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'
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) => {
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)