supabase / auth-js

An isomorphic Javascript library for Supabase Auth.
MIT License
356 stars 160 forks source link

feat: support more than one digit of pagination metadata in `listUsers()` #793

Open makeusabrew opened 11 months ago

makeusabrew commented 11 months ago

What kind of change does this PR introduce?

Fixes an issue where the pagination metadata returned from listUsers() was inaccurate for page values >= 10.

What is the current behavior?

The current behaviour assumes the page value contained in the link string (each element of which looks a bit like this: </admin/users?page=7&per_page=10>; rel="last") is always a single digit, leading to truncated values for nextPage and lastPage being returned if either are 10 or more. For example, if nextPage is 10, the current behaviour truncates this to 1. If the client is relying on the value of nextPage, this could cause it to paginate up to page 9 correctly but then reset to page 1 rather than move on to page 10.

What is the new behavior?

The new behaviour correctly parses multi-digit values for nextPage and lastPage.

Additional context

I couldn't get the test suite running but didn't see any tests relating to this so I don't think any tests will break. I patched the proposed changes into the project I have which was being tripped up by this behaviour and they appear to work as expected. Feel free to refactor - wasn't sure if changing the various split() calls to a regex was a no-no.

Thanks!