Documentation Index
Fetch the complete documentation index at: https://www.dynamic.xyz/docs/llms.txt
Use this file to discover all available pages before exploring further.
refreshUser
Refreshes the current user’s data from the server. This function fetches the latest authenticated user information from the backend and updates the local user state.
Use this when you need to ensure the user’s profile data is synchronized with the server, such as after making changes to the user’s account information.
Usage
import { refreshUser } from '@dynamic-labs-sdk/client';
const updateUserData = async () => {
const user = await refreshUser();
console.log('User refreshed:', user);
};
Parameters
| Parameter | Type | Description |
|---|
client | DynamicClient (optional) | The Dynamic client instance. Only required when using multiple clients. |
Returns
Promise<SdkUser> - A promise that resolves to the authenticated user object with updated data.
Examples
Basic usage
import { refreshUser } from '@dynamic-labs-sdk/client';
const handleProfileUpdate = async () => {
// After updating user profile on the backend
await updateUserProfile();
// Refresh user to get the latest data
const updatedUser = await refreshUser();
console.log('Updated user:', updatedUser);
};
import { refreshUser } from '@dynamic-labs-sdk/client';
function ProfileUpdateButton() {
const handleUpdate = async () => {
await updateUserProfile();
await refreshUser();
// userChanged fires — any useUser() consumers re-render automatically
};
return <button onClick={handleUpdate}>Sync profile</button>;
}
Listen to user changes
import { refreshUser, onEvent } from '@dynamic-labs-sdk/client';
onEvent({
event: 'userChanged',
listener: ({ user }) => {
console.log('User data updated:', user);
},
});
await refreshUser();
Components using useUser() re-render automatically when userChanged fires — no manual listener needed. If you need a side-effect on change, register it once at app level.import { onEvent } from '@dynamic-labs-sdk/client';
import { useEffect } from 'react';
function useUserChangeLogger() {
useEffect(() => {
return onEvent({
event: 'userChanged',
listener: ({ user }) => console.log('User updated:', user),
});
}, []);
}
Handle wallet account changes
import { refreshUser, onEvent } from '@dynamic-labs-sdk/client';
onEvent({
event: 'walletAccountsChanged',
listener: ({ walletAccounts }) => {
console.log('Wallet accounts updated:', walletAccounts);
},
});
await refreshUser();
Components using useWalletAccounts() re-render automatically when walletAccountsChanged fires after a refreshUser() call.