Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Conversation

makeusabrew
Copy link

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!

if (links.length > 0) {
const regex = /page=(\d+)(?=&)[^>]*>; rel="(\w+)"/
links.forEach((link: string) => {
const page = parseInt(link.split(';')[0].split('=')[1].substring(0, 1))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .substring(0, 1) here is the cause of the truncation

@hf hf changed the title fix: support more than one digit of pagination metadata in listUsers() feat: support more than one digit of pagination metadata in listUsers() Oct 25, 2023
hf
hf previously approved these changes Oct 25, 2023
Copy link
Contributor

@hf hf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this! We've got an outstanding item to fix the pagination in GoTrue but it's going to be a while.

@hf hf dismissed their stale review October 25, 2023 09:52

Sorry one thing.

const total = response.headers.get('x-total-count') ?? 0
const links = response.headers.get('link')?.split(',') ?? []
if (links.length > 0) {
const regex = /page=(\d+)(?=&)[^>]*>; rel="(\w+)"/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually would you mind pulling this regex up to the top scope, so that a new object is not being created every time the function is called?

Also, is it possible to not use a regex here at all? Maybe use URLSearchParams instead?

@mandarini
Copy link
Contributor

Thank you very much for your contribution @makeusabrew ! Great catch!! :D I will close this PR now, because it's been so long (sorry about that). My plan is to eventually get this PR ready to merge. However, if you have time and want to, you can use the solution suggested in that PR and create a new PR instead!

Again, thank you so much for contributing to Supabase!

@mandarini mandarini closed this Sep 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants