diff --git a/apps/api/src/app/auth/dtos/register-user.dto.ts b/apps/api/src/app/auth/dtos/register-user.dto.ts index 108541f6..ed0fc722 100644 --- a/apps/api/src/app/auth/dtos/register-user.dto.ts +++ b/apps/api/src/app/auth/dtos/register-user.dto.ts @@ -1,5 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; -import { IsDefined, IsString, IsEmail, IsOptional } from 'class-validator'; +import { IsDefined, IsString, IsEmail, IsOptional, MaxLength } from 'class-validator'; export class RegisterUserDto { @ApiProperty({ @@ -28,6 +28,7 @@ export class RegisterUserDto { }) @IsString() @IsDefined() + @MaxLength(24) password: string; @ApiProperty({ diff --git a/apps/api/src/app/auth/dtos/reset-password.dto.ts b/apps/api/src/app/auth/dtos/reset-password.dto.ts index 93412696..2d03c5e1 100644 --- a/apps/api/src/app/auth/dtos/reset-password.dto.ts +++ b/apps/api/src/app/auth/dtos/reset-password.dto.ts @@ -1,9 +1,10 @@ import { ApiProperty } from '@nestjs/swagger'; -import { IsDefined, IsString, IsUUID } from 'class-validator'; +import { IsDefined, IsString, IsUUID, MaxLength } from 'class-validator'; export class ResetPasswordDto { @IsString() @IsDefined() + @MaxLength(24) @ApiProperty({ description: 'New password of the user', }) diff --git a/apps/web/config/constants.config.ts b/apps/web/config/constants.config.ts index 9ab32ab1..c16770dd 100644 --- a/apps/web/config/constants.config.ts +++ b/apps/web/config/constants.config.ts @@ -24,6 +24,7 @@ export const CONSTANTS = { 'An error occurred with the payment. No amount has been deducted. Please try again later or contact the support team.', SUBSCRIPTION_ACTIVATED_TITLE: 'Subscription activated', SUBSCRIPTION_FAILED_TITLE: 'Payment failed', + MAX_PASSWORD_LENGTH: 24 }; export const VARIABLES = { @@ -463,7 +464,7 @@ export enum PLANCODEENUM { GROWTH_YEARLY = 'GROWTH-YEARLY', STARTER = 'STARTER', } -export const plans: { monthly: Plan[]; yearly: Plan[] } = { +export const plans: { monthly: Plan[]; yearly: Plan[]; } = { monthly: [ { name: 'Starter (Default)', diff --git a/apps/web/hooks/auth/useResetPassword.tsx b/apps/web/hooks/auth/useResetPassword.tsx index f5ee592a..8747dbe7 100644 --- a/apps/web/hooks/auth/useResetPassword.tsx +++ b/apps/web/hooks/auth/useResetPassword.tsx @@ -3,7 +3,7 @@ import { useRouter } from 'next/router'; import { useForm } from 'react-hook-form'; import { useMutation } from '@tanstack/react-query'; -import { API_KEYS, ROUTES } from '@config'; +import { API_KEYS, CONSTANTS, ROUTES } from '@config'; import { commonApi } from '@libs/api'; import { IErrorObject, ILoginResponse, SCREENS } from '@impler/shared'; import { track } from '@libs/amplitude'; @@ -19,7 +19,11 @@ interface IResetPasswordData extends IResetPasswordFormData { export function useResetPassword() { const { push, query } = useRouter(); - const { register, handleSubmit } = useForm(); + const { + register, + handleSubmit, + setError, + formState: { errors }, } = useForm(); const { mutate: resetPassword, isLoading: isResetPasswordLoading, @@ -49,6 +53,12 @@ export function useResetPassword() { }; const onResetPassword = (data: IResetPasswordFormData) => { + if (data.password && data.password.length > CONSTANTS.MAX_PASSWORD_LENGTH) { + setError("password", { + type: "manual", + message: `Password length must be less than ${CONSTANTS.MAX_PASSWORD_LENGTH}!` + }); + } resetPassword({ ...data, token: query.token as string, @@ -57,6 +67,7 @@ export function useResetPassword() { return { error, + errors, isError, register, goToLogin, diff --git a/apps/web/hooks/auth/useSignup.tsx b/apps/web/hooks/auth/useSignup.tsx index af4db274..29f5d272 100644 --- a/apps/web/hooks/auth/useSignup.tsx +++ b/apps/web/hooks/auth/useSignup.tsx @@ -5,7 +5,7 @@ import { useForm } from 'react-hook-form'; import { useMutation, useQuery } from '@tanstack/react-query'; import { notify } from '@libs/notify'; -import { API_KEYS, NOTIFICATION_KEYS, ROUTES } from '@config'; +import { API_KEYS, CONSTANTS, NOTIFICATION_KEYS, ROUTES } from '@config'; import { commonApi } from '@libs/api'; import { track } from '@libs/amplitude'; import { useAppState } from 'store/app.context'; @@ -40,7 +40,7 @@ export function useSignup() { const [isInvitationLink, setIsInvitationLink] = useState(); const invitationId = query.invitationId as string | undefined; - const { isLoading: isAcceptingInvitation, isError } = useQuery( + const { isLoading: isAcceptingInvitation, isError } = useQuery( [API_KEYS.GET_TEAM_INVITATIONS, invitationId], () => commonApi(API_KEYS.GET_TEAM_INVITATIONS as any, { @@ -99,6 +99,13 @@ export function useSignup() { }); const onSignup = (data: ISignupFormData) => { + if (data.password && data.password.length > CONSTANTS.MAX_PASSWORD_LENGTH) { + setError("password", { + type: "manual", + message: `Password length must be less than ${CONSTANTS.MAX_PASSWORD_LENGTH}!` + }); + return; + } const signupData: ISignupData = { firstName: data.fullName.split(' ')[0], lastName: data.fullName.split(' ')[1], diff --git a/apps/web/pages/auth/reset/[token].tsx b/apps/web/pages/auth/reset/[token].tsx index 78310ac2..1b8bae9a 100644 --- a/apps/web/pages/auth/reset/[token].tsx +++ b/apps/web/pages/auth/reset/[token].tsx @@ -9,8 +9,8 @@ import { OnboardLayout } from '@layouts/OnboardLayout'; import { useResetPassword } from '@hooks/auth/useResetPassword'; import { PLACEHOLDERS, ROUTES, colors } from '@config'; -export default function ResetPasswordPage({}) { - const { register, resetPassword, error, isError } = useResetPassword(); +export default function ResetPasswordPage({ }) { + const { register, resetPassword, error, isError, errors } = useResetPassword(); return ( <> @@ -44,9 +44,9 @@ export default function ResetPasswordPage({}) { Back to Signin - {isError && ( + {isError || errors.password.message && ( - {error?.message} + {error?.message || errors.password.message} )}