Skip to content

Commit 8463eb3

Browse files
authored
fix-ENG-45 (#601)
1 parent 2e3cace commit 8463eb3

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

apps/platform/trpc/routers/authRouter/passwordRouter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export const passwordRouter = router({
168168
.use(ratelimiter({ limit: 20, namespace: 'signIn.password' }))
169169
.input(
170170
z.object({
171-
username: zodSchemas.username(2),
171+
username: zodSchemas.usernameLogin(2),
172172
password: z.string().min(8)
173173
})
174174
)

apps/platform/trpc/routers/authRouter/recoveryRouter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const recoveryRouter = router({
2727
.input(
2828
z
2929
.object({
30-
username: zodSchemas.username(2),
30+
username: zodSchemas.usernameLogin(2),
3131
recoveryCode: zodSchemas.nanoIdToken()
3232
})
3333
.and(

apps/platform/trpc/routers/orgRouter/mail/emailIdentityRouter.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ export const emailIdentityRouter = router({
3232
checkEmailAvailability: orgProcedure
3333
.input(
3434
z.object({
35-
emailUsername: z.string().min(1).max(255),
35+
emailUsername: z
36+
.string()
37+
.min(1)
38+
.max(255)
39+
.regex(/^[a-zA-Z0-9._-]*$/, {
40+
message: 'Only letters, numbers, dots, hyphens and underscores'
41+
}),
3642
domainPublicId: typeIdValidator('domains')
3743
})
3844
)
@@ -89,7 +95,13 @@ export const emailIdentityRouter = router({
8995
createNewEmailIdentity: orgAdminProcedure
9096
.input(
9197
z.object({
92-
emailUsername: z.string().min(1).max(255),
98+
emailUsername: z
99+
.string()
100+
.min(1)
101+
.max(255)
102+
.regex(/^[a-zA-Z0-9._-]*$/, {
103+
message: 'Only letters, numbers, dots, hyphens and underscores'
104+
}),
93105
domainPublicId: typeIdValidator('domains'),
94106
sendName: z.string().min(2).max(255),
95107
catchAll: z.boolean().optional().default(false),

packages/utils/zodSchemas.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,19 @@ export const zodSchemas = {
4040
message: `Must be at least ${minLength} characters long`
4141
})
4242
.max(32, {
43-
message: "Too Long, Ain't nobody typing that 😂"
43+
message: 'Too Long'
44+
})
45+
.regex(/^[a-zA-Z0-9]*$/, {
46+
message: 'Only letters and numbers'
47+
}),
48+
usernameLogin: (minLength: number = 5) =>
49+
z
50+
.string()
51+
.min(minLength, {
52+
message: `Must be at least ${minLength} characters long`
53+
})
54+
.max(32, {
55+
message: 'Too Long'
4456
})
4557
.regex(/^[a-zA-Z0-9._-]*$/, {
4658
message: 'Only letters and numbers'

0 commit comments

Comments
 (0)