@@ -7,10 +7,10 @@ import { FormLabel } from '@/components/ui/form/FormLabel';
77import { FormMessage } from '@/components/ui/form/FormMessage' ;
88import { Input } from '@/components/ui/input' ;
99import { logoutOnSuccess } from '@/features/auth/handlers/logoutOnSuccess' ;
10- import { getCurrentUser } from '@/features/auth/queries/getCurrentUser' ;
1110import { useUpdateUserMutation } from '@/features/profile/mutations/updateUserMutation' ;
1211import { UpdateUserSchema } from '@/features/profile/mutations/updateUserSchema' ;
1312import { useCloudAuth } from '@/hooks/useAuth' ;
13+ import { authStore , OverallAppSignIn } from '@/lib/authStore' ;
1414import { zodResolver } from '@hookform/resolvers/zod' ;
1515import { useNavigate , useRouter } from '@tanstack/react-router' ;
1616import { Save } from 'lucide-react' ;
@@ -23,17 +23,15 @@ export function ProfileIndex() {
2323 const router = useRouter ( ) ;
2424 const navigate = useNavigate ( ) ;
2525 const { user } = useCloudAuth ( ) ;
26+
2627 const form = useForm ( {
2728 resolver : zodResolver ( UpdateUserSchema ) ,
28- defaultValues : async ( ) => {
29- const user = await getCurrentUser ( ) ;
30- return {
31- confirmNewPassword : '' ,
32- firstname : user . firstname ,
33- id : user . id ,
34- lastname : user . lastname ,
35- newPassword : '' ,
36- } ;
29+ defaultValues : {
30+ confirmNewPassword : '' ,
31+ firstname : user ?. firstname || '' ,
32+ id : user ?. id || '' ,
33+ lastname : user ?. lastname || '' ,
34+ newPassword : '' ,
3735 } ,
3836 } ) ;
3937 const { mutate : updateUser , isPending : isUpdatePending } = useUpdateUserMutation ( ) ;
@@ -43,7 +41,11 @@ export function ProfileIndex() {
4341 if ( formData ) {
4442 updateUser ( formData , {
4543 onSuccess : ( data ) => {
46- form . reset ( data ) ;
44+ form . reset ( {
45+ ...form . formState . defaultValues ,
46+ ...data ,
47+ } ) ;
48+ authStore . updateUserForEntity ( OverallAppSignIn , data ) ;
4749 if ( formData . newPassword ) {
4850 toast . success ( 'Profile updated successfully!' , {
4951 description : 'Please sign in with your new password.' ,
@@ -158,7 +160,6 @@ export function ProfileIndex() {
158160 ) }
159161 />
160162
161-
162163 < div className = "flex justify-between w-full" >
163164 < Button
164165 type = "submit"
0 commit comments