From 41cf7778fe86963a74955b5bc7859057073d86a1 Mon Sep 17 00:00:00 2001 From: Charles Bochet Date: Mon, 22 Jul 2024 17:22:45 +0200 Subject: [PATCH] Fix reset PasswordToken --- packages/twenty-front/project.json | 2 +- .../src/effect-components/PageChangeEffect.tsx | 4 +++- .../twenty-front/src/pages/auth/PasswordReset.tsx | 14 +++++++++----- .../auth/dto/password-reset-token.input.ts | 11 ----------- 4 files changed, 13 insertions(+), 18 deletions(-) delete mode 100644 packages/twenty-server/src/engine/core-modules/auth/dto/password-reset-token.input.ts diff --git a/packages/twenty-front/project.json b/packages/twenty-front/project.json index 4c427109b051..636fd29af6a6 100644 --- a/packages/twenty-front/project.json +++ b/packages/twenty-front/project.json @@ -61,7 +61,7 @@ "test": {}, "storybook:build": { "options": { - "env": { "NODE_OPTIONS": "--max_old_space_size=5000" } + "env": { "NODE_OPTIONS": "--max_old_space_size=6000" } } }, "storybook:serve:dev": { diff --git a/packages/twenty-front/src/effect-components/PageChangeEffect.tsx b/packages/twenty-front/src/effect-components/PageChangeEffect.tsx index a49b3c29bd1b..78578016605c 100644 --- a/packages/twenty-front/src/effect-components/PageChangeEffect.tsx +++ b/packages/twenty-front/src/effect-components/PageChangeEffect.tsx @@ -165,7 +165,9 @@ export const PageChangeEffect = () => { useEffect(() => { if ( isCaptchaScriptLoaded && - isMatchingLocation(AppPath.SignInUp || AppPath.Invite) + (isMatchingLocation(AppPath.SignInUp) || + isMatchingLocation(AppPath.Invite) || + isMatchingLocation(AppPath.ResetPassword)) ) { requestFreshCaptchaToken(); } diff --git a/packages/twenty-front/src/pages/auth/PasswordReset.tsx b/packages/twenty-front/src/pages/auth/PasswordReset.tsx index f40e98c3e817..79ea7074021d 100644 --- a/packages/twenty-front/src/pages/auth/PasswordReset.tsx +++ b/packages/twenty-front/src/pages/auth/PasswordReset.tsx @@ -1,12 +1,12 @@ -import { useState } from 'react'; -import { Controller, useForm } from 'react-hook-form'; -import Skeleton, { SkeletonTheme } from 'react-loading-skeleton'; -import { useNavigate, useParams } from 'react-router-dom'; import { useTheme } from '@emotion/react'; import styled from '@emotion/styled'; import { zodResolver } from '@hookform/resolvers/zod'; import { isNonEmptyString } from '@sniptt/guards'; import { motion } from 'framer-motion'; +import { useState } from 'react'; +import { Controller, useForm } from 'react-hook-form'; +import Skeleton, { SkeletonTheme } from 'react-loading-skeleton'; +import { useNavigate, useParams } from 'react-router-dom'; import { useSetRecoilState } from 'recoil'; import { z } from 'zod'; @@ -15,6 +15,7 @@ import { Title } from '@/auth/components/Title'; import { useAuth } from '@/auth/hooks/useAuth'; import { useIsLogged } from '@/auth/hooks/useIsLogged'; import { PASSWORD_REGEX } from '@/auth/utils/passwordRegex'; +import { useReadCaptchaToken } from '@/captcha/hooks/useReadCaptchaToken'; import { AppPath } from '@/types/AppPath'; import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar'; import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar'; @@ -118,6 +119,7 @@ export const PasswordReset = () => { useUpdatePasswordViaResetTokenMutation(); const { signInWithCredentials } = useAuth(); + const { readCaptchaToken } = useReadCaptchaToken(); const onSubmit = async (formData: Form) => { try { @@ -143,7 +145,9 @@ export const PasswordReset = () => { return; } - await signInWithCredentials(email || '', formData.newPassword); + const token = await readCaptchaToken(); + + await signInWithCredentials(email || '', formData.newPassword, token); navigate(AppPath.Index); } catch (err) { logError(err); diff --git a/packages/twenty-server/src/engine/core-modules/auth/dto/password-reset-token.input.ts b/packages/twenty-server/src/engine/core-modules/auth/dto/password-reset-token.input.ts deleted file mode 100644 index 5120af2942c6..000000000000 --- a/packages/twenty-server/src/engine/core-modules/auth/dto/password-reset-token.input.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { ArgsType, Field } from '@nestjs/graphql'; - -import { IsEmail, IsNotEmpty } from 'class-validator'; - -@ArgsType() -export class PasswordResetTokenInput { - @Field(() => String) - @IsNotEmpty() - @IsEmail() - email: string; -}