How long before updated user info visible through Management API search?

In my Next.js app (using the app router if that matters), I regularly need to update the app_metadata and/or user_metadata, which is working as expected. However, afterwards, I want to refresh the list of users within my app with their current data (e.g., updated accountStatus field within their app_metadata), but it’s not updating. I understand that getting a list of users is “eventually consistent”, but what is the reasonable amount of time before consistency is guaranteed? As of right now, I’m still not seeing updates that were made yesterday!

Update user code

// app/api/users/[id]/route.js

import { ManagementClient } from 'auth0';

// Update a user
export async function PUT(request, { params }) {
    try {
        const body = await request.json();
        const { id } = params;

        const management = new ManagementClient({
            domain: process.env.AUTH0_DOMAIN,
            clientId: process.env.AUTH0_CLIENT_ID,
            clientSecret: process.env.AUTH0_CLIENT_SECRET
        });

        const updatedUser = await management.users.update({ id }, body);

        return new Response(JSON.stringify({ message: 'User updated successfully' }), { status: 201 }); // 201 Created
    } catch(error) {
        console.error('User update error:', error);
        return new Response(JSON.stringify({ message: 'User update failed' }), { status: 500 }); // Generic fallback
    }
}

Get users code

// app/api/users/route.js

import { ManagementClient } from 'auth0';

// Get all users
export async function GET() {
    const management = new ManagementClient({
        domain: process.env.AUTH0_DOMAIN,
        clientId: process.env.AUTH0_CLIENT_ID,
        clientSecret: process.env.AUTH0_CLIENT_SECRET
    });

    const getAllUsersResponse = await management.users.getAll();
    return Response.json(getAllUsersResponse.data);
}

Hi @richardcarrigan,

The updated user info should be available immediately after an update using the Management API.

I performed a test using the Management API to update the user’s app_metadata and get the user profile afterward. In my result, I saw the updated app_metadata information in their user profile.

I called the Update a user, Get a user, and List or Search Users endpoints and got the updated information in the user’s profile.

For example, if the user data had the following:

{
  app_metadata: {
    "accountStatus": "inactive"
  }
}

Then, to update the "accountStatus" value to something else, you would pass the following:

{
  app_metadata: {
    "accountStatus": "active"
  }
}

After reviewing your code, I noticed that the id may not be properly referenced.

I recommend improving the readability of your code by doing something like the following:

const userId = 'auth0|1234567890';
const body = {
  app_metadata: {
    "accountStatus": "active"
  }
};
const updatedUser = await management.users.update({ id: userId }, body);

(Reference: UsersManager | auth0)

Thanks,
Rueben

Thanks for the quick reply, @rueben.tiow , but this is not a solution. As I said, the update is working as expected, so refactoring for readability isn’t going to fix anything. My get users request is also successful in the sense that I receive a list of users, but the data isn’t current. I’m actually still not seeing changes made since 2 days ago now, so maybe there’s an issue with my tenant configuration?

FWIW, here’s an example request being sent to my API route to update the user:

// components/UserList.jsx

async function approveAccount(userId) {
  const response = await fetch(`/api/users/${userId}`, {
    method: 'PUT',
    body: JSON.stringify({
      app_metadata: {
        accountStatus: 'approved'
      }
    })
  });
}

P.S. - I’m not sure if this helps with diagnosing the issue, but I also don’t see new users that were created yesterday through the Management API, so something is definitely wrong, either with my code (not sure what it could be though) or with my tenant/account config. Does it matter that I’m on a Free account and/or creating fictitious users?

Hi @richardcarrigan,

Thanks for the update.

Can you confirm if you see those updated changes after updating the user and checking their user profile on the Dashboard?

Or vice versa, if you make changes to the user’s profile on the Dashboard, can you see those changes when calling the Get a user endpoint?

As an additional test, could you try using the Management API Update a user endpoint and Get a user endpoint to see if the updates to the user profile work as expected?

Let me know your findings.

Thanks,
Rueben

Ok, I think we’re getting closer to identifying the root cause. Updating the user through the Management API works fine (i.e., I can see the change in the dashboard). However, I’m unable to see the updated user info from my app, whether using the users.get method for a single user or the users.getAll method for all users, but I am able to see the updated user info when using the Get a user endpoint. Here’s the relevant code:

// app/api/users/route.js

import { ManagementClient } from 'auth0';

// Get all users
export async function GET() {
    const management = new ManagementClient({
        domain: process.env.AUTH0_DOMAIN,
        clientId: process.env.AUTH0_CLIENT_ID,
        clientSecret: process.env.AUTH0_CLIENT_SECRET
    });

    const getAllUsersResponse = await management.users.getAll();
    return Response.json(getAllUsersResponse.data);
}
// app/api/users/route.js

import { ManagementClient } from 'auth0';

// Get a single user
export async function GET(request, { params }) {
    const { id } = params;

    const management = new ManagementClient({
        domain: process.env.AUTH0_DOMAIN,
        clientId: process.env.AUTH0_CLIENT_ID,
        clientSecret: process.env.AUTH0_CLIENT_SECRET
    });

    const getUserResponse = await management.users.get({ id });
    return Response.json(getUserResponse.data);
}

I finally figured it out. It turns out that the data was being cached in the browser due to how my Next.js app was configured. After upgrading from Next.js v14 to v15, the issue has been resolved.