Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.
Closed
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