Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

Fix bug (#1402)

Sean Boult158ab7338f5d
diff --git a/apps/web/src/app/[locale]/settings/_components/schema.ts b/apps/web/src/app/[locale]/settings/_components/schema.ts
index a06535d7..13860162 100644
--- a/apps/web/src/app/[locale]/settings/_components/schema.ts
+++ b/apps/web/src/app/[locale]/settings/_components/schema.ts
@@ -13,13 +13,30 @@ export const appearanceFormSchema = z.object({
export type ApperenceFormSchema = z.infer<typeof appearanceFormSchema>;
+// returns true/false if the url contains a https/http proto
+const validUrlWithHttpOrHttps = z.string().refine(
+ (url) => {
+ try {
+ const parsedUrl = new URL(url);
+ return ['https:', 'http:'].includes(parsedUrl.protocol);
+ } catch (error) {
+ return false;
+ }
+ },
+ {
+ message: "URL must have the 'http(s)' protocol",
+ },
+);
+
export const profileSchema = z.object({
bio: createNoProfanitySchemaWithValidate((str) => str.max(256)),
userLinks: z.array(
z.object({
id: z.union([z.string(), z.null()]),
url: z.union([
- createNoProfanitySchemaWithValidate((str) => str.url().max(256)),
+ createNoProfanitySchemaWithValidate((str) => str.url().max(256)).and(
+ validUrlWithHttpOrHttps,
+ ),
z.literal(''),
]),
}),