mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 08:42:12 +10:00
chore: refactor
This commit is contained in:
@ -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',
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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',
|
||||
|
||||
Reference in New Issue
Block a user