From e62559c52f0d8de0dce3dee5e884c485e20c1365 Mon Sep 17 00:00:00 2001 From: Zai Shi Date: Tue, 21 Jan 2025 10:40:39 -0800 Subject: [PATCH] fixed domain list problem --- .../[projectId]/domains/page-client.tsx | 21 +++++++++++++++++-- packages/stack-shared/src/schema-fields.ts | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) 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