Customizing Polling Behavior in useUser Hook

I’m currently using the useUser hook from the Auth0 Next.js SDK in my application. Upon reviewing the SDK’s documentation and source code, I’ve observed that the hook utilizes useSWR internally to fetch user data from the /auth/profile endpoint. This setup introduces polling behavior, as useSWR periodically re-fetches data to keep it up-to-date.

However, the SDK does not provide a direct way to customize the polling behavior via the useUser hook. I’m seeking guidance on how to manage polling behavior, such as adjusting the refresh interval or disabling polling, to optimize network requests and application performance.

Steps to Reproduce:

  1. Install the Auth0 Next.js SDK.

  2. Use the useUser hook in a component.

  3. Observe the network requests to the /auth/profile endpoint.

Expected Behavior:

The ability to customize the polling behavior of the useUser hook, including adjusting the refresh interval or disabling polling, to optimize network requests and application performance.

Actual Behavior:

The SDK does not provide a direct way to customize the polling behavior via the useUser hook.

Environment:

  • Auth0 Next.js SDK version: ^4.9.0

  • Next.js version: 15.5.2

Additional Context:

Customizing the polling behavior is crucial for optimizing network requests and application performance, especially in scenarios where user data changes infrequently. Providing a way to manage polling behavior would enhance the flexibility and efficiency of the SDK.

Hi @Yazan-Ali9 and welcome to the Auth0 Community!

You are right that you cannot modify the options passed to the useSWR hook when using the useUser hook so there isn’t much I can help you with there. What I would do is try to create a custom implementation of the useUser hook using the one from the repo as an example.

Here is the SWR docs as well, in case you haven’t already found it yourself.

You can also try to create a feature-request for the options to be added.

I wish you a great day!
Teodor.