🛂 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 (
|
if (
|
||||||
typebot.customDomain &&
|
typebot.customDomain &&
|
||||||
(await isCustomDomainNotAvailable(typebot.customDomain))
|
(await isCustomDomainNotAvailable({
|
||||||
|
customDomain: typebot.customDomain,
|
||||||
|
workspaceId,
|
||||||
|
}))
|
||||||
)
|
)
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: 'BAD_REQUEST',
|
code: 'BAD_REQUEST',
|
||||||
|
|||||||
@@ -131,7 +131,10 @@ export const updateTypebot = authenticatedProcedure
|
|||||||
if (
|
if (
|
||||||
typebot.customDomain &&
|
typebot.customDomain &&
|
||||||
existingTypebot.customDomain !== typebot.customDomain &&
|
existingTypebot.customDomain !== typebot.customDomain &&
|
||||||
(await isCustomDomainNotAvailable(typebot.customDomain))
|
(await isCustomDomainNotAvailable({
|
||||||
|
customDomain: typebot.customDomain,
|
||||||
|
workspaceId: existingTypebot.workspace.id,
|
||||||
|
}))
|
||||||
)
|
)
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: 'BAD_REQUEST',
|
code: 'BAD_REQUEST',
|
||||||
|
|||||||
@@ -123,7 +123,21 @@ export const isPublicIdNotAvailable = async (publicId: string) => {
|
|||||||
return typebotWithSameIdCount > 0
|
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({
|
const typebotWithSameDomainCount = await prisma.typebot.count({
|
||||||
where: {
|
where: {
|
||||||
customDomain,
|
customDomain,
|
||||||
|
|||||||
Reference in New Issue
Block a user