2
0

🛂 Make sure to check the domain exists before updating it on typebot

This commit is contained in:
Baptiste Arnaud
2024-02-21 17:56:12 +01:00
parent ddb7ac7915
commit e4d2ebefcc
3 changed files with 23 additions and 3 deletions

View File

@ -67,7 +67,10 @@ export const createTypebot = authenticatedProcedure
if (
typebot.customDomain &&
(await isCustomDomainNotAvailable(typebot.customDomain))
(await isCustomDomainNotAvailable({
customDomain: typebot.customDomain,
workspaceId,
}))
)
throw new TRPCError({
code: 'BAD_REQUEST',

View File

@ -131,7 +131,10 @@ export const updateTypebot = authenticatedProcedure
if (
typebot.customDomain &&
existingTypebot.customDomain !== typebot.customDomain &&
(await isCustomDomainNotAvailable(typebot.customDomain))
(await isCustomDomainNotAvailable({
customDomain: typebot.customDomain,
workspaceId: existingTypebot.workspace.id,
}))
)
throw new TRPCError({
code: 'BAD_REQUEST',

View File

@ -123,7 +123,21 @@ export const isPublicIdNotAvailable = async (publicId: string) => {
return typebotWithSameIdCount > 0
}
export const isCustomDomainNotAvailable = async (customDomain: string) => {
export const isCustomDomainNotAvailable = async ({
customDomain,
workspaceId,
}: {
customDomain: string
workspaceId: string
}) => {
const domainCount = await prisma.customDomain.count({
where: {
workspaceId,
name: customDomain.split('/')[0],
},
})
if (domainCount === 0) return true
const typebotWithSameDomainCount = await prisma.typebot.count({
where: {
customDomain,