Skip to content

Commit

Permalink
🐛 Fix issues with email change flow (#1495)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukevella authored Jan 14, 2025
1 parent ff3d992 commit 4e2661b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion apps/web/public/locales/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,5 +289,5 @@
"emailChangeRequestSentDescription": "To complete the change, please check your email for a verification link.",
"profileEmailAddress": "Email Address",
"profileEmailAddressDescription": "Your email address is used to log in to your account",
"emailAlreadyInUse": "Email already in use. Please try a different one or delete the existing account."
"emailAlreadyInUse": "This email address is already associated with another account. Please use a different email address."
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { usePostHog } from "@rallly/posthog/client";
import { Alert, AlertDescription, AlertTitle } from "@rallly/ui/alert";
import { Button } from "@rallly/ui/button";
Expand All @@ -16,23 +17,26 @@ import { InfoIcon } from "lucide-react";
import React from "react";
import { useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { z } from "zod";

import { Trans } from "@/components/trans";
import { useUser } from "@/components/user-provider";
import { trpc } from "@/trpc/client";

const emailChangeFormData = z.object({
email: z.string().email(),
});

type EmailChangeFormData = z.infer<typeof emailChangeFormData>;
export const ProfileEmailAddress = () => {
const { user, refresh } = useUser();
const requestEmailChange = trpc.user.requestEmailChange.useMutation();
const posthog = usePostHog();
const form = useForm<{
name: string;
email: string;
}>({
const form = useForm<EmailChangeFormData>({
defaultValues: {
name: user.isGuest ? "" : user.name,
email: user.email ?? "",
},
resolver: zodResolver(emailChangeFormData),
});
const { t } = useTranslation("app");
const { toast } = useToast();
Expand Down Expand Up @@ -82,7 +86,6 @@ export const ProfileEmailAddress = () => {
<Form {...form}>
<form
onSubmit={handleSubmit(async (data) => {
reset(data);
if (data.email !== user.email) {
posthog.capture("email change requested");
const res = await requestEmailChange.mutateAsync({
Expand All @@ -99,9 +102,9 @@ export const ProfileEmailAddress = () => {
}
} else {
setDidRequestEmailChange(true);
reset(data);
}
}
await refresh();
})}
>
<div className="flex flex-col gap-y-4">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { Button } from "@rallly/ui/button";
import {
Form,
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@rallly/ui/form";
import { Input } from "@rallly/ui/input";
import { useForm } from "react-hook-form";
import { z } from "zod";

import { ProfilePicture } from "@/app/[locale]/(admin)/settings/profile/profile-picture";
import { Trans } from "@/components/trans";
import { useUser } from "@/components/user-provider";
import { trpc } from "@/trpc/client";

const profileSettingsFormData = z.object({
name: z.string().min(1).max(100),
});

type ProfileSettingsFormData = z.infer<typeof profileSettingsFormData>;

export const ProfileSettings = () => {
const { user, refresh } = useUser();
const changeName = trpc.user.changeName.useMutation();

const form = useForm<{
name: string;
email: string;
}>({
const form = useForm<ProfileSettingsFormData>({
defaultValues: {
name: user.isGuest ? "" : user.name,
email: user.email ?? "",
},
resolver: zodResolver(profileSettingsFormData),
});

const { control, handleSubmit, formState, reset } = form;
Expand Down Expand Up @@ -54,6 +60,7 @@ export const ProfileSettings = () => {
<FormControl>
<Input id="name" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
Expand Down
2 changes: 1 addition & 1 deletion packages/emails/locales/en/emails.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@
"changeEmailRequest_text2": "To complete this change, please click the button below:",
"changeEmailRequest_button": "Verify Email Address",
"changeEmailRequest_subject": "Verify your new email address",
"changeEmailRequest_text3": "This link will expire in 10 minutes. If you did not request this change, please contact support.",
"changeEmailRequest_text3": "This link will expire in 10 minutes. If you did not request this change, please ignore this email.",
"changeEmailRequest_text1": "We've received a request to change the email address for your account from <b>{{fromEmail}}</b> to <b>{{toEmail}}</b>."
}

0 comments on commit 4e2661b

Please sign in to comment.