chore: refactor

This commit is contained in:
Catalin Pit
2024-01-25 15:42:40 +02:00
parent ffee2b2c9a
commit 49ecfc1a2c
7 changed files with 13 additions and 66 deletions

View File

@ -20,25 +20,15 @@ export default function UnverifiedAccount() {
const token = searchParams?.get('t') ?? '';
const { data: { email } = {} } = trpc.profile.getUserFromVerificationToken.useQuery({ token });
const { mutateAsync: sendConfirmationEmail } = trpc.profile.sendConfirmationEmail.useMutation();
const onResendConfirmationEmail = async () => {
if (!email) {
toast({
title: 'Unable to send confirmation email',
description: 'Something went wrong while sending the confirmation email. Please try again.',
variant: 'destructive',
});
return;
}
try {
setIsButtonDisabled(true);
await sendConfirmationEmail({ email: email });
// TODO: decrypt email and send it
await sendConfirmationEmail({ email: token ?? '' });
toast({
title: 'Success',

View File

@ -62,6 +62,8 @@ export const SignInForm = ({ className, isGoogleSSOEnabled }: SignInFormProps) =
useState(false);
const router = useRouter();
const { mutateAsync: encryptSecondaryData } = trpc.crypto.encryptSecondaryData.useMutation();
const [twoFactorAuthenticationMethod, setTwoFactorAuthenticationMethod] = useState<
'totp' | 'backup'
>('totp');
@ -76,8 +78,6 @@ export const SignInForm = ({ className, isGoogleSSOEnabled }: SignInFormProps) =
resolver: zodResolver(ZSignInFormSchema),
});
const { mutateAsync: getUser } = trpc.profile.getUserByEmail.useMutation();
const isSubmitting = form.formState.isSubmitting;
const onCloseTwoFactorAuthenticationDialog = () => {
@ -132,10 +132,9 @@ export const SignInForm = ({ className, isGoogleSSOEnabled }: SignInFormProps) =
const errorMessage = ERROR_MESSAGES[result.error];
if (result.error === ErrorCode.UNVERIFIED_EMAIL) {
const user = await getUser({ email });
const token = user?.VerificationToken[user.VerificationToken.length - 1].token;
const encryptedEmail = await encryptSecondaryData({ data: email });
router.push(`/unverified-account?t=${token}`);
router.push(`/unverified-account?t=${encryptedEmail}`);
return;
}

View File

@ -62,12 +62,15 @@ export const SignUpForm = ({ className, isGoogleSSOEnabled }: SignUpFormProps) =
const isSubmitting = form.formState.isSubmitting;
const { mutateAsync: signup } = trpc.auth.signup.useMutation();
const { mutateAsync: encryptSecondaryData } = trpc.crypto.encryptSecondaryData.useMutation();
const onFormSubmit = async ({ name, email, password, signature }: TSignUpFormSchema) => {
try {
await signup({ name, email, password, signature });
router.push('/signin');
const encryptedEmail = await encryptSecondaryData({ data: email });
router.push(`/unverified-account?t=${encryptedEmail}`);
toast({
title: 'Registration Successful',