auth0 / node-auth0

Node.js client library for the Auth0 platform.
MIT License
628 stars 307 forks source link

next cursor is provided when getting a list of members, but no members returned #966

Closed malinskibeniamin closed 10 months ago

malinskibeniamin commented 10 months ago

Checklist

Description

According to Auth0 docs, if we request a list of members, we can get either of these types:

export type GetMembers200Response = Array<GetMembers200ResponseOneOfInner> | GetMembers200ResponseOneOf | GetMembers200ResponseOneOf1;

Unfortunately, in Auth0 docs page under Checkpoint Pagination, it says you will only get the next property if there are more records to be retrieved, but at times the fetch will yield 0 results (empty array will get returned).

Note: The first time you call this endpoint using Checkpoint Pagination, you should omit the from parameter. If there are more results, a next value will be included in the response. You can use this for subsequent API calls. When next is no longer included in the response, this indicates there are no more pages remaining.

We should either update the docs to say that there might be an empty list despite the next cursor being provided, or fix the issue if it's a bug.

Reproduction

  1. Call auth0.organizations.getMembers()
  2. Get some results and next
  3. Call the function again with next cursor page token
  4. Get an empty list of results

Additional context

No response

node-auth0 version

v4.1.0

Node.js version

v18.12.1

frederikprijck commented 10 months ago

Thanks for reaching out. Can you verify if this eventualy resolves (and whether this is an async timing issue) or if it stays empty?

malinskibeniamin commented 10 months ago

Thanks for reaching out. Can you verify if this eventualy resolves (and whether this is an async timing issue) or if it stays empty?

@frederikprijck Thanks for a quick reply! This has been an issue in our integration environment, it can be reproduced consistently both locally and with a deployed API - we have fixed it by adding an if statement so that despite the next property being provided when no results are remaining to be fetched, we just omit that part and return the previous list. We had to add a test scenario to mirror this behaviour, it caught us by surprise given the docs specified otherwise.

Originally I figured some records must have been deleted right at that moment, but it's not true. Auth0 always returns next 1 additional time for us - we still attempt to fetch more results, at which point we double check the list is not empty, just as a sanity check.

Disclaimer: I would suggest we add an extra type where there is a members property without next field present, as that is what we were getting.

frederikprijck commented 10 months ago

I don't think this is anything related to the SDK, nor something we can solve from our SDK side. Our SDK passes through anything the API returns.

Can you verify the same response is returned if you call the API outside of our SDK?

If so, i recommend reaching out to your point of contact at auth0 to get you in touch with the correct team, that way this issue can be looked at more directly and it will be easier to troubleshoot.

frederikprijck commented 10 months ago

As I was curious what could be causing this I looked into this and I was able to reproduce this. After further investigation, it turns out this is how the checkpoint pagination works.

It is expected that if the last page contains exactly the same amount of items as the take parameter, a next will be included that points to an empty page.

Closing this as it seems to work as designed, you can always pass along the feedback to your contact at Auth0 or provide feedback here.