From 52959fe257808b4868a7d6ed5b7275a724831bab Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Wed, 21 Sep 2022 05:41:08 +0100 Subject: [PATCH] Fixes password prompt race condition (#4644) --- .../pages/v2/settings/my-account/profile.tsx | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/apps/web/pages/v2/settings/my-account/profile.tsx b/apps/web/pages/v2/settings/my-account/profile.tsx index 17662f3228..a1adce67e0 100644 --- a/apps/web/pages/v2/settings/my-account/profile.tsx +++ b/apps/web/pages/v2/settings/my-account/profile.tsx @@ -1,6 +1,6 @@ import crypto from "crypto"; import { signOut } from "next-auth/react"; -import { useRef, useState, BaseSyntheticEvent } from "react"; +import { useRef, useState, BaseSyntheticEvent, useEffect } from "react"; import { Controller, useForm } from "react-hook-form"; import { ErrorCode } from "@calcom/lib/auth"; @@ -124,15 +124,26 @@ const ProfileView = () => { deleteMeMutation.mutate({ password, totpCode }); }; - const formMethods = useForm({ - defaultValues: { - avatar: user?.avatar || "", - username: user?.username || "", - name: user?.name || "", - email: user?.email || "", - bio: user?.bio || "", - }, - }); + const formMethods = useForm<{ + avatar?: string; + username?: string; + name?: string; + email?: string; + bio?: string; + }>(); + + const { reset } = formMethods; + + useEffect(() => { + if (user) + reset({ + avatar: user?.avatar || "", + username: user?.username || "", + name: user?.name || "", + email: user?.email || "", + bio: user?.bio || "", + }); + }, [reset, user]); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const passwordRef = useRef(null!);