diff --git a/apps/dashboard/src/app/(main)/(protected)/projects/[projectId]/domains/page-client.tsx b/apps/dashboard/src/app/(main)/(protected)/projects/[projectId]/domains/page-client.tsx index c0b7ff5c4..eb5987f01 100644 --- a/apps/dashboard/src/app/(main)/(protected)/projects/[projectId]/domains/page-client.tsx +++ b/apps/dashboard/src/app/(main)/(protected)/projects/[projectId]/domains/page-client.tsx @@ -46,7 +46,24 @@ function EditDialog(props: { addWww: yup.boolean(), }); - const canAddWww = (domain: string | undefined) => domain && isValidUrl('https://' + domain) && !domain.startsWith('www.') && isValidUrl('https://www.' + domain); + const canAddWww = (domain: string | undefined) => { + if (!domain) { + return false; + } + + const httpsUrl = 'https://' + domain; + if (!isValidUrl(httpsUrl)) { + return false; + } + + if (domain.startsWith('www.')) { + return false; + } + + const wwwUrl = 'https://www.' + domain; + console.log(wwwUrl, isValidUrl(wwwUrl)); + return isValidUrl(wwwUrl); + }; return value?.startsWith('https://')).meta({ openapiField: { description: 'Your domain URL. Make sure you own and trust this domain. Needs to start with https://', exampleValue: 'https://example.com' } }); +export const projectTrustedDomainSchema = urlSchema.test('is-https', 'Trusted domain must start with https://', (value) => value?.startsWith('https://')).meta({ openapiField: { description: 'Your domain URL. Make sure you own and trust this domain. Needs to start with https://', exampleValue: 'https://example.com' } }); export const handlerPathSchema = yupString().test('is-handler-path', 'Handler path must start with /', (value) => value?.startsWith('/')).meta({ openapiField: { description: 'Handler path. If you did not setup a custom handler path, it should be "/handler" by default. It needs to start with /', exampleValue: '/handler' } }); // Users