diff --git a/src/contexts/AuthContext.tsx b/src/contexts/AuthContext.tsx index 03ec072..675b834 100644 --- a/src/contexts/AuthContext.tsx +++ b/src/contexts/AuthContext.tsx @@ -13,6 +13,7 @@ type AuthContextData = { user: UserDTO; signIn: (email: string, password: string) => Promise; signOut: () => Promise; + updateUserData: (userData: UserDTO) => Promise; isLoadingUserStorageData: boolean; }; @@ -71,6 +72,15 @@ export function AuthContextProvider({ children }: AuthContextProviderProps) { } } + async function updateUserData(userData: UserDTO) { + try { + setUser(userData); + await storageUserSave(userData); + } catch (error) { + throw error; + } + } + async function loadUserData() { try { setIsLoadingUserStorageData(true); @@ -93,7 +103,8 @@ export function AuthContextProvider({ children }: AuthContextProviderProps) { }, []); return ( - + {children} ); diff --git a/src/screens/Profile.tsx b/src/screens/Profile.tsx index 510ca10..f725291 100644 --- a/src/screens/Profile.tsx +++ b/src/screens/Profile.tsx @@ -53,7 +53,7 @@ export function Profile() { const [userPhoto, setUserPhoto] = useState('https://i.pravatar.cc/200'); const toast = useToast(); - const { user } = useAuth(); + const { user, updateUserData } = useAuth(); const { control, @@ -79,6 +79,11 @@ export function Profile() { password: data.new_password, old_password: data.old_password, }); + + const updatedUserData = user; + updatedUserData.name = data.name; + updateUserData(updatedUserData); + toast.show({ placement: 'top', render: ({ id }) => (