> ## 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.

# useRefreshAuth

<Card title="Recommended: JavaScript SDK with React Hooks" icon="react" href="/javascript/reference/react-quickstart" color="#4779FE">
  For new React apps, we recommend the JavaScript SDK with React Hooks (`@dynamic-labs-sdk/react-hooks`) instead of the legacy React SDK documented here. The JS SDK comes with many benefits such as a much smaller bundle size and other optimizations. Use the [React quickstart (JavaScript SDK)](/javascript/reference/react-quickstart) to get started.
</Card>

## Summary

Used to manually refresh both the user state and authentication token at any point in time. This hook is useful when you need to ensure the user's authentication data is synchronized with the server, such as after making changes to the user's account or when the JWT token needs to be refreshed.

Unlike [`useRefreshUser`](/react-sdk/hooks/login-user-management/userefreshuser), which only refreshes user data, `useRefreshAuth` refreshes both the user information and the JWT token, ensuring complete authentication state synchronization.

The SDK state as a whole will be maintained i.e. the `sdkHasLoaded` boolean on `useDynamicContext` will stay true. If you want to reset the whole SDK including wallets, then take a look at [`useReinitialize`](/react-sdk/hooks/usereinitialize).

## Usage

```tsx theme={"system"}
import {
  DynamicContextProvider,
  useRefreshAuth,
} from '@dynamic-labs/sdk-react-core';

const RefreshAuthButton = () => {
  const refreshAuth = useRefreshAuth();

  const handleRefresh = async () => {
    try {
      const user = await refreshAuth();
      console.log('Auth refreshed:', user);
    } catch (error) {
      console.error('Failed to refresh auth:', error);
    }
  };

  return <button onClick={handleRefresh}>Refresh Auth</button>;
};

const App = () => {
  return (
    <DynamicContextProvider>
      <RefreshAuthButton />
    </DynamicContextProvider>
  );
};
```

## Return Value

Returns a callback function that:

* Returns `Promise<UserProfile | undefined>` when called
* Refreshes both user data and JWT token from the server
* Updates the SDK state with the latest authentication information
* Throws an error if the refresh results in an invalid user state

## FAQs

**When exactly is the JWT updated?**

* The JWT is updated on every successful call. On failure, nothing is mutated, so the existing JWT remains as-is (still usable until it actually expires)

**Is there a client-side rate limit?**

* No, there's no client-side limit, so it would come down to [general rate limits](/overview/rate-limits) at that point.

**What's the difference between useRefreshAuth and useRefreshUser?**

* `useRefreshAuth` refreshes both user data AND the JWT token from the server
* `useRefreshUser` only refreshes user data without updating the JWT token
* Use `useRefreshAuth` when you need to ensure complete authentication state synchronization
* Use `useRefreshUser` when you only need to sync user profile information
