Skip to content

Commit

Permalink
fix: support more than one digit of pagination metadata in listUsers()
Browse files Browse the repository at this point in the history
  • Loading branch information
makeusabrew committed Oct 11, 2023
1 parent b4494cb commit 0fd3289
Showing 1 changed file with 7 additions and 3 deletions.
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+)"/
links.forEach((link: string) => {
const page = parseInt(link.split(';')[0].split('=')[1].substring(0, 1))
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

0 comments on commit 0fd3289

Please sign in to comment.