diff --git a/packages/backend/src/types.ts b/packages/backend/src/types.ts index ce587bf..7e6e7da 100644 --- a/packages/backend/src/types.ts +++ b/packages/backend/src/types.ts @@ -1,25 +1,42 @@ -import { isAddress } from "viem"; -import z from "zod"; +import { isAddress } from 'viem'; +import z from 'zod'; export const SendOtpSchema = z.object({ - email: z.string().email().endsWith("@pse.dev").refine(email => !email.includes('+'), { - message: "Email must not contain '+'" - }), + email: z + .string() + .email() + .refine( + (email) => { + return ( + (email.endsWith('@pse.dev') || email.endsWith('@ethereum.org')) && !email.includes('+') + ); + }, + { + message: "Email must be from '@pse.dev' or '@ethereum.org' and must not contain '+'" + } + ) }); export type SendOtp = z.infer; export const VerifyOtpSchema = z.object({ - email: z.string() + email: z + .string() .email() - .endsWith("@pse.dev") - .refine(email => !email.includes('+'), { - message: "Email must not contain '+'" - }), + .refine( + (email) => { + return ( + (email.endsWith('@pse.dev') || email.endsWith('@ethereum.org')) && !email.includes('+') + ); + }, + { + message: "Email must be from '@pse.dev' or '@ethereum.org' and must not contain '+'" + } + ), otp: z.number().int().gte(100000).lte(999999), address: z.string().refine(isAddress, { - message: "Invalid address", - }), + message: 'Invalid address' + }) }); export type VerifyOtp = z.infer; diff --git a/packages/interface/src/features/signup/components/RegisterEmail.tsx b/packages/interface/src/features/signup/components/RegisterEmail.tsx index 4fc9494..1221d32 100644 --- a/packages/interface/src/features/signup/components/RegisterEmail.tsx +++ b/packages/interface/src/features/signup/components/RegisterEmail.tsx @@ -1,62 +1,62 @@ -import { Dispatch, SetStateAction, useState } from "react"; -import { toast } from "sonner"; +import { Dispatch, SetStateAction, useState } from "react" +import { toast } from "sonner" -import { config } from "~/config"; -import { Form, FormControl, FormSection } from "~/components/ui/Form"; -import { Input } from "~/components/ui/Input"; -import { EmailFieldSchema, EmailField } from "../types"; -import { Button } from "~/components/ui/Button"; -import { Spinner } from "~/components/ui/Spinner"; +import { config } from "~/config" +import { Form, FormControl, FormSection } from "~/components/ui/Form" +import { Input } from "~/components/ui/Input" +import { EmailFieldSchema, EmailField } from "../types" +import { Button } from "~/components/ui/Button" +import { Spinner } from "~/components/ui/Spinner" interface IRegisterEmailProps { emailField: - | { - email: string; - } - | undefined; + | { + email: string + } + | undefined setEmail: Dispatch< SetStateAction< | { - email: string; - } + email: string + } | undefined > - >; + > } const RegisterEmail = ({ emailField, setEmail, }: IRegisterEmailProps): JSX.Element => { - const [registering, setRegistering] = useState(false); + const [registering, setRegistering] = useState(false) const registerEmail = async (emailField: EmailField) => { try { - setRegistering(true); + setRegistering(true) const response = await fetch(`${config.backendUrl}/send-otp`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(emailField), - }); - const json = await response.json(); + }) + const json = await response.json() if (!response.ok) { - console.log(response.status); - console.error(json); - toast.error((json.errors && json.errors[0]) ?? json.message); + console.log(response.status) + console.error(json) + toast.error((json.errors && json.errors[0]) ?? json.message) } else { - setEmail(emailField); - toast.success(`OTP has been sent to ${emailField.email}`); + setEmail(emailField) + toast.success(`OTP has been sent to ${emailField.email}`) } } catch (error: any) { - console.error(error); - toast.error("An unexpected error occured registering your email"); + console.error(error) + toast.error("An unexpected error occured registering your email") } finally { - setRegistering(false); + setRegistering(false) } - }; + } return (
@@ -65,16 +65,16 @@ const RegisterEmail = ({ onSubmit={(email) => registerEmail(email)} > - +
- ); -}; + ) +} -export default RegisterEmail; +export default RegisterEmail diff --git a/packages/interface/src/features/signup/components/VerifyOtp.tsx b/packages/interface/src/features/signup/components/VerifyOtp.tsx index 5256896..544bed9 100644 --- a/packages/interface/src/features/signup/components/VerifyOtp.tsx +++ b/packages/interface/src/features/signup/components/VerifyOtp.tsx @@ -157,7 +157,7 @@ const VerifyOtp = ({ emailField }: IVerifyOtpProps): JSX.Element => {