Skip to content

Commit 27969dd

Browse files
committed
fix: Consistently trim and lowercase usernames and emails
https://harperdb.atlassian.net/browse/STUDIO-420
1 parent e437a88 commit 27969dd

File tree

13 files changed

+56
-57
lines changed

13 files changed

+56
-57
lines changed

src/features/auth/ForgotPassword.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { FormField } from '@/components/ui/form/FormField';
44
import { FormItem } from '@/components/ui/form/FormItem';
55
import { FormLabel } from '@/components/ui/form/FormLabel';
66
import { FormMessage } from '@/components/ui/form/FormMessage';
7+
import { zodRequireEmail } from '@/lib/zod/email';
78
import { Link, useNavigate } from '@tanstack/react-router';
89
import { useForgotPasswordMutation } from '@/features/auth/hooks/useForgotPassword';
910
import { useForm } from 'react-hook-form';
@@ -14,11 +15,7 @@ import { Button } from '@/components/ui/button';
1415
import { toast } from 'sonner';
1516

1617
const ForgotPasswordSchema = z.object({
17-
email: z
18-
.email({
19-
error: 'Please enter a valid email address.',
20-
})
21-
.max(75, { error: 'Email cannot be longer than 75 characters.' }),
18+
email: zodRequireEmail,
2219
});
2320

2421
export function ForgotPassword() {

src/features/auth/ResetPassword.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { FormItem } from '@/components/ui/form/FormItem';
66
import { FormLabel } from '@/components/ui/form/FormLabel';
77
import { FormMessage } from '@/components/ui/form/FormMessage';
88
import { Input } from '@/components/ui/input';
9+
import { zodRequirePassword } from '@/lib/zod/password';
910
import { zodResolver } from '@hookform/resolvers/zod';
1011
import { useNavigate, useSearch } from '@tanstack/react-router';
1112
import { useEffect } from 'react';
@@ -16,8 +17,7 @@ import { useResetPasswordMutation } from './hooks/useResetPassword';
1617

1718
const ResetPasswordSchema = z
1819
.object({
19-
password: z
20-
.string()
20+
password: zodRequirePassword
2121
.min(8, { error: 'Password must be at least 8 characters long.' })
2222
.max(50, { error: 'Password cannot be longer than 50 characters.' }),
2323
confirmPassword: z.string(),

src/features/auth/SignIn.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { reoClient } from '@/integrations/reo/reo';
1111
import { authStore, OverallAppSignIn } from '@/lib/authStore';
1212
import { parseCompanyFromEmail } from '@/lib/string/parseCompanyFromEmail';
1313
import { getDefaultSignedInCloudRouteForUser } from '@/lib/urls/getDefaultSignedInCloudRouteForUser';
14+
import { zodRequireEmail } from '@/lib/zod/email';
15+
import { zodRequirePassword } from '@/lib/zod/password';
1416
import { queryKeys } from '@/react-query/constants';
1517
import { zodResolver } from '@hookform/resolvers/zod';
1618
import { useQueryClient } from '@tanstack/react-query';
@@ -19,13 +21,8 @@ import { useForm } from 'react-hook-form';
1921
import { z } from 'zod';
2022

2123
const SignInSchema = z.object({
22-
email: z
23-
.email({
24-
error: 'Please enter a valid email address.',
25-
}),
26-
password: z
27-
.string()
28-
.nonempty({ error: 'Please enter your password.' }),
24+
email: zodRequireEmail,
25+
password: zodRequirePassword,
2926
});
3027

3128
export function SignIn() {

src/features/auth/SignUp.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@ import { FormLabel } from '@/components/ui/form/FormLabel';
77
import { FormMessage } from '@/components/ui/form/FormMessage';
88
import { Input } from '@/components/ui/input';
99
import { useSignUpMutation } from '@/features/auth/hooks/useSignUp';
10+
import { zodRequireEmail } from '@/lib/zod/email';
11+
import { zodRequirePassword } from '@/lib/zod/password';
1012
import { zodResolver } from '@hookform/resolvers/zod';
1113
import { Link, useNavigate, useSearch } from '@tanstack/react-router';
1214
import { useForm } from 'react-hook-form';
1315
import { toast } from 'sonner';
1416
import { z } from 'zod';
1517

1618
const SignInSchema = z.object({
17-
email: z
18-
.email({
19-
error: 'Please enter a valid email address.',
20-
})
21-
.trim()
22-
.toLowerCase()
19+
email: zodRequireEmail
2320
.max(80, { error: 'Email cannot be longer than 80 characters.' }),
2421
firstname: z
2522
.string()
@@ -31,8 +28,7 @@ const SignInSchema = z.object({
3128
.trim()
3229
.min(2, { error: 'Please enter your last name.' })
3330
.max(80, { error: 'Last name cannot be longer than 80 characters.' }),
34-
password: z
35-
.string()
31+
password: zodRequirePassword
3632
.min(8, { error: 'Password must be at least 8 characters long.' }),
3733
});
3834

@@ -150,7 +146,10 @@ export function SignUp() {
150146
</FormItem>
151147
)}
152148
/>
153-
<p className="text-xs">By creating an account, you agree to the <a rel="noopener" href="https://www.harpersystems.dev/legal/privacy-policy" target="_blank" className="underline">Privacy Policy</a> and <a rel="noopener" href="https://www.harpersystems.dev/legal/harperdb-cloud-terms-of-service" target="_blank" className="underline">Terms of Service</a></p>
149+
<p className="text-xs">By creating an account, you agree to
150+
the <a rel="noopener" href="https://www.harpersystems.dev/legal/privacy-policy" target="_blank" className="underline">Privacy
151+
Policy</a> and <a rel="noopener" href="https://www.harpersystems.dev/legal/harperdb-cloud-terms-of-service" target="_blank" className="underline">Terms
152+
of Service</a></p>
154153

155154
<Button type="submit" variant="submit" className="w-full my-2 rounded-full">
156155
Sign Up For Free

src/features/auth/VerifyEmail.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { FormLabel } from '@/components/ui/form/FormLabel';
77
import { FormMessage } from '@/components/ui/form/FormMessage';
88
import { Input } from '@/components/ui/input';
99
import { useVerifyEmailMutation, VerifyEmailToken } from '@/features/auth/hooks/useVerifyEmail';
10+
import { zodRequireEmail } from '@/lib/zod/email';
1011
import { zodResolver } from '@hookform/resolvers/zod';
1112
import { useNavigate, useSearch } from '@tanstack/react-router';
1213
import { useCallback, useEffect } from 'react';
@@ -16,11 +17,7 @@ import { z } from 'zod';
1617
import { useResendEmailVerification } from './hooks/useResendEmailVerification';
1718

1819
const VerifyEmailSchema = z.object({
19-
email: z
20-
.email({
21-
error: 'Please enter a valid email address.',
22-
})
23-
.max(75, { error: 'Email cannot be longer than 75 characters.' }),
20+
email: zodRequireEmail,
2421
});
2522

2623
function SendEmailVerification() {

src/features/instance/operations/schemas/addUserFormSchema.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1+
import { zodRequirePassword } from '@/lib/zod/password';
2+
import { zodRequireUsername } from '@/lib/zod/username';
13
import { z } from 'zod';
24

35
export const AddUserFormSchema = z
46
.object({
5-
username: z
6-
.string()
7-
.trim()
8-
.toLowerCase()
9-
.nonempty({ error: 'Please enter a username.' }),
7+
username: zodRequireUsername,
108
role: z
119
.string()
1210
.nonempty({
1311
error: 'Please select a role.',
1412
}),
15-
password: z
16-
.string()
13+
password: zodRequirePassword
1714
.min(8, { error: 'Password must be at least 8 characters long.' }),
1815
confirmPassword: z.string(),
1916
})

src/features/instance/operations/schemas/deleteUserFormSchema.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1+
import { zodRequireUsername } from '@/lib/zod/username';
12
import { z } from 'zod';
23

34
export const DeleteUserFormSchema = z.object({
4-
username: z
5-
.string()
6-
.nonempty({
7-
error: 'Please enter a username.',
8-
}),
5+
username: zodRequireUsername,
96
confirmUsernameForDeletion: z
107
.string()
118
.nonempty({
129
error: 'Please type the username again to confirm deletion.',
13-
}),
10+
})
11+
.toLowerCase(),
1412
})
1513
.refine((data) => data.username === data.confirmUsernameForDeletion, {
1614
error: 'Username does not match.',
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1+
import { zodRequirePassword } from '@/lib/zod/password';
2+
import { zodRequireUsername } from '@/lib/zod/username';
13
import { z } from 'zod';
24

35
export const SignInSchema = z.object({
4-
username: z
5-
.string()
6-
.nonempty({ error: 'Please enter your username.' }),
7-
password: z
8-
.string()
9-
.nonempty({ error: 'Please enter your password.' }),
6+
username: zodRequireUsername,
7+
password: zodRequirePassword,
108
});

src/features/organization/mutations/addUserToOrganizationRole.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { apiClient } from '@/config/apiClient';
2+
import { zodRequireEmail } from '@/lib/zod/email';
23
import { useMutation } from '@tanstack/react-query';
34
import z from 'zod';
45

56
export const AddOrganizationRoleSchema = z.object({
6-
email: z
7-
.email({
8-
error: 'Please enter a valid email address.',
9-
})
10-
.max(75, { error: 'Email cannot be longer than 75 characters.' }),
7+
email: zodRequireEmail
8+
.max(80, { error: 'Email cannot be longer than 80 characters.' }),
119
roleId: z.string().nonempty({ error: 'Please select a role.' }),
1210
});
1311

src/features/organization/mutations/inviteUserToOrganizationRole.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { apiClient } from '@/config/apiClient';
2+
import { zodRequireEmail } from '@/lib/zod/email';
23
import { useMutation } from '@tanstack/react-query';
34
import z from 'zod';
45

56
export const InviteOrganizationRoleSchema = z.object({
6-
email: z
7-
.email({
8-
error: 'Please enter a valid email address.',
9-
})
10-
.max(75, { error: 'Email cannot be longer than 75 characters.' }),
7+
email: zodRequireEmail
8+
.max(80, { error: 'Email cannot be longer than 80 characters.' }),
119
roleId: z.string().nonempty({ error: 'Please select a role.' }),
1210
});
1311

0 commit comments

Comments
 (0)