Skip to content

Commit

Permalink
fix(clerk-js): Do not send stale field value when creating email addr…
Browse files Browse the repository at this point in the history
…ess and username (#4713)

Co-authored-by: panteliselef <[email protected]>
  • Loading branch information
LauraBeatris and panteliselef authored Dec 4, 2024
1 parent 3d58082 commit 5150fa1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-shrimps-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Fixes an issue in `UserProfile` where email and username forms could retain stale values from the previous render, leading to incorrect data being sent to FAPI
4 changes: 2 additions & 2 deletions packages/clerk-js/src/ui/components/UserProfile/EmailForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const EmailForm = withCardStateProvider((props: EmailFormProps) => {
const environment = useEnvironment();
const preferEmailLinks = emailLinksEnabledForInstance(environment);

const [createEmailAddress] = useReverification(() => user?.createEmailAddress({ email: emailField.value }));
const [createEmailAddress] = useReverification((email: string) => user?.createEmailAddress({ email }));

const emailAddressRef = React.useRef<EmailAddressResource | undefined>(user?.emailAddresses.find(a => a.id === id));
const wizard = useWizard({
Expand All @@ -44,7 +44,7 @@ export const EmailForm = withCardStateProvider((props: EmailFormProps) => {
if (!user) {
return;
}
return createEmailAddress()
return createEmailAddress(emailField.value)
.then(res => {
emailAddressRef.current = res;
wizard.nextStep();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const UsernameForm = withCardStateProvider((props: UsernameFormProps) =>
const { onSuccess, onReset } = props;
const { user } = useUser();

const [updateUsername] = useReverification(() => user?.update({ username: usernameField.value }));
const [updateUsername] = useReverification((username: string) => user?.update({ username }));

const { userSettings } = useEnvironment();
const card = useCardState();
Expand All @@ -33,7 +33,7 @@ export const UsernameForm = withCardStateProvider((props: UsernameFormProps) =>

const submitUpdate = async () => {
try {
await updateUsername();
await updateUsername(usernameField.value);
onSuccess();
} catch (e) {
handleError(e, [usernameField], card.setError);
Expand Down

0 comments on commit 5150fa1

Please sign in to comment.