Documentation Index
Fetch the complete documentation index at: https://docs.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);
};
Listen to user changes
import { refreshUser, onEvent } from '@dynamic-labs-sdk/client';
// Set up listener for user changes
onEvent({
event: 'userChanged',
listener: ({ user }) => {
console.log('User data updated:', user);
},
});
// Trigger refresh - will fire userChanged event if data changed
await refreshUser();
Handle wallet account changes
import { refreshUser, onEvent } from '@dynamic-labs-sdk/client';
// Listen for wallet account changes triggered by user refresh
onEvent({
event: 'walletAccountsChanged',
listener: ({ walletAccounts }) => {
console.log('Wallet accounts updated:', walletAccounts);
},
});
// Refresh user data - will also check for wallet changes
await refreshUser();