🛂 Make sure to check the domain exists before updating it on typebot
This commit is contained in:
@ -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',
|
||||
|
@ -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',
|
||||
|
@ -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,
|
||||
|
Reference in New Issue
Block a user