2
0
Files
bot/apps/builder/src/pages/api/publicIdAvailable.ts
Baptiste Arnaud 0febaf9760 🚸 (publish) Improve invalid public ID feedback
Also remove the 4 char min length rule for self-hosted versions

Closes #267
2023-01-20 11:20:11 +01:00

20 lines
678 B
TypeScript

import prisma from '@/lib/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { methodNotAllowed, notAuthenticated } from 'utils/api'
import { getAuthenticatedUser } from '@/features/auth/api'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
if (!user) return notAuthenticated(res)
if (req.method === 'GET') {
const publicId = req.query.publicId as string | undefined
const exists = await prisma.typebot.count({
where: { publicId: publicId ?? '' },
})
return res.send({ isAvailable: Boolean(!exists) })
}
return methodNotAllowed(res)
}
export default handler