Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/GoTrueAdminApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,14 @@ export default class GoTrueAdminApi {
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?

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

const rel = JSON.parse(link.split(';')[1].split('=')[1])
pagination[`${rel}Page`] = page
const match = regex.exec(link.trim())
if (match) {
const page = parseInt(match[1], 10)
const rel = match[2]
pagination[`${rel}Page`] = page
}
})

pagination.total = parseInt(total)
Expand Down
Loading