mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +10:00
chore: refactor
This commit is contained in:
@ -18,7 +18,7 @@ export default function UnverifiedAccount() {
|
|||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
const encryptedEmail = searchParams?.get('t') ?? ''; // TODO: choose a better name instead of t
|
const encryptedEmail = searchParams?.get('token') ?? '';
|
||||||
|
|
||||||
const { mutateAsync: sendConfirmationEmail } = trpc.profile.sendConfirmationEmail.useMutation();
|
const { mutateAsync: sendConfirmationEmail } = trpc.profile.sendConfirmationEmail.useMutation();
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ export default function UnverifiedAccount() {
|
|||||||
try {
|
try {
|
||||||
setIsButtonDisabled(true);
|
setIsButtonDisabled(true);
|
||||||
|
|
||||||
await sendConfirmationEmail({ email: encryptedEmail });
|
await sendConfirmationEmail({ encryptedEmail });
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: 'Success',
|
title: 'Success',
|
||||||
|
|||||||
@ -134,7 +134,7 @@ export const SignInForm = ({ className, isGoogleSSOEnabled }: SignInFormProps) =
|
|||||||
if (result.error === ErrorCode.UNVERIFIED_EMAIL) {
|
if (result.error === ErrorCode.UNVERIFIED_EMAIL) {
|
||||||
const encryptedEmail = await encryptSecondaryData({ data: email });
|
const encryptedEmail = await encryptSecondaryData({ data: email });
|
||||||
|
|
||||||
router.push(`/unverified-account?t=${encryptedEmail}`);
|
router.push(`/unverified-account?token=${encryptedEmail}`);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -70,7 +70,7 @@ export const SignUpForm = ({ className, isGoogleSSOEnabled }: SignUpFormProps) =
|
|||||||
|
|
||||||
const encryptedEmail = await encryptSecondaryData({ data: email });
|
const encryptedEmail = await encryptSecondaryData({ data: email });
|
||||||
|
|
||||||
router.push(`/unverified-account?t=${encryptedEmail}`);
|
router.push(`/unverified-account?token=${encryptedEmail}`);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: 'Registration Successful',
|
title: 'Registration Successful',
|
||||||
|
|||||||
@ -37,7 +37,6 @@ export const sendConfirmationToken = async ({ email }: { email: string }) => {
|
|||||||
throw new Error(`Failed to create the verification token`);
|
throw new Error(`Failed to create the verification token`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Revisit tomorrow
|
|
||||||
try {
|
try {
|
||||||
await sendConfirmationEmail({ userId: user.id });
|
await sendConfirmationEmail({ userId: user.id });
|
||||||
|
|
||||||
|
|||||||
@ -135,11 +135,15 @@ export const profileRouter = router({
|
|||||||
.input(ZConfirmEmailMutationSchema)
|
.input(ZConfirmEmailMutationSchema)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input }) => {
|
||||||
try {
|
try {
|
||||||
const { email } = input;
|
const { encryptedEmail } = input;
|
||||||
|
|
||||||
const decryptedEmail = decryptSecondaryData(email);
|
const decryptedEmail = decryptSecondaryData(encryptedEmail);
|
||||||
|
|
||||||
return await sendConfirmationToken({ email: decryptedEmail ?? '' }); // TODO: fix this tomorrow
|
if (!decryptedEmail) {
|
||||||
|
throw new Error('Email is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
return await sendConfirmationToken({ email: decryptedEmail });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
let message = 'We were unable to send a confirmation email. Please try again.';
|
let message = 'We were unable to send a confirmation email. Please try again.';
|
||||||
|
|
||||||
|
|||||||
@ -30,9 +30,9 @@ export const ZResetPasswordFormSchema = z.object({
|
|||||||
password: z.string().min(6),
|
password: z.string().min(6),
|
||||||
token: z.string().min(1),
|
token: z.string().min(1),
|
||||||
});
|
});
|
||||||
// TODO: revisit this
|
|
||||||
export const ZConfirmEmailMutationSchema = z.object({
|
export const ZConfirmEmailMutationSchema = z.object({
|
||||||
email: z.string().min(1),
|
encryptedEmail: z.string().min(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type TRetrieveUserByIdQuerySchema = z.infer<typeof ZRetrieveUserByIdQuerySchema>;
|
export type TRetrieveUserByIdQuerySchema = z.infer<typeof ZRetrieveUserByIdQuerySchema>;
|
||||||
|
|||||||
Reference in New Issue
Block a user