check for namespace domain before blocking org check

This commit is contained in:
miloschwartz
2026-08-31 10:55:17 -04:00
parent bc56a2bed0
commit dd0a5a359a
+10 -15
View File
@@ -31,7 +31,6 @@ export async function validateAndConstructDomain(
subdomain?: string | null subdomain?: string | null
): Promise<DomainValidationResult> { ): Promise<DomainValidationResult> {
try { try {
// Query domain with organization access check
const [domainRes] = await db const [domainRes] = await db
.select() .select()
.from(domains) .from(domains)
@@ -42,6 +41,10 @@ export async function validateAndConstructDomain(
eq(orgDomains.orgId, orgId), eq(orgDomains.orgId, orgId),
eq(orgDomains.domainId, domainId) eq(orgDomains.domainId, domainId)
) )
)
.leftJoin(
domainNamespaces,
eq(domainNamespaces.domainId, domainId)
); );
// Check if domain exists // Check if domain exists
@@ -52,7 +55,7 @@ export async function validateAndConstructDomain(
}; };
} }
if (!domainRes.orgDomains) { if (!domainRes.orgDomains && !domainRes.domainNamespaces) {
return { return {
success: false, success: false,
error: `Organization does not have access to domain with ID ${domainId}` error: `Organization does not have access to domain with ID ${domainId}`
@@ -83,19 +86,11 @@ export async function validateAndConstructDomain(
} }
// Wildcard subdomains are not allowed on namespace (provided/free) domains // Wildcard subdomains are not allowed on namespace (provided/free) domains
if (isWildcard) { if (isWildcard && domainRes.domainNamespaces) {
const [namespaceDomain] = await db return {
.select() success: false,
.from(domainNamespaces) error: "Wildcard subdomains are not supported for provided or free domains. Use a specific subdomain instead."
.where(eq(domainNamespaces.domainId, domainId)) };
.limit(1);
if (namespaceDomain) {
return {
success: false,
error: "Wildcard subdomains are not supported for provided or free domains. Use a specific subdomain instead."
};
}
} }
if ( if (