Hey all, I seem to be having an issue now that I have reached over 50 users of my website. I am using gotrue-js with Netlify Identity, it seems that it requests only a limit of 50 or there may be some other issues? I have read through the documentation as far as I can tell for gotrue, and gotrue-js looking for paginations or limit related code, however, I cannot find anything?
I have also tried reading through @jonsully cool wrapper for netlify identity seen here: GitHub - jon-sully/react-netlify-identity-gotrue: A pure React (hooks-based) API to Netlify Identity / GoTrue, fully implementing all auth workflows to see if there was a get users function handled there.
The code of the function is as follows: (I added the limit as a test)
I can’t seem to find the prior post where someone else asked about the same issue and I directed them to the somewhat-undocumented page parameter available on all GoTrue endpoints. The tl;dr: here is that I wouldn’t use the gotrue-js library for admin-level requests you’re running from functions. I know it supports them (sorta?) but still, it’ll be easier for you if you just manually setup your request in the function with a fetch (using node-fetch, really). Here’s an example from my React-GoTrue integration demo site, gatsby-identity-demo (all code here), that runs an admin-level action (adding/removing a role from a user) against the site’s GoTrue instance.
I’d recommend giving that a full read, but essentially it just runs a PUT against the GoTrue instance, whose hostname/URL you can get from the context.
Anyway, pagination. What you’re seeing is page 1 of the results, and the page size is capped to 50 per page by default. You have two options. First, you could just request pages 2, then 3, etc. until you get all the results. How many results are there? You should be receiving a header in the response with key X-Total-Count that tells you, and I think another header with key Link that would get you to the next or last page. Not sure which, you may need to play with it.
You can also just specify a bigger page size, but that has performance implications too. If you have a thousand users and tell GoTrue to just send back all thousand in one page, you may hit timeouts. You just need to add a query-string parameter of per_page=xxx, so {identityHostEtc..}/admin/users?per_page=100.
Hope that helps! As always, YMMV
–
Jon
EDIT: Found it:
EDIT2: Thanks for the plug on the react library I wrote (missed that earlier) — it does indeed work great for end users but it’s not made to execute admin-level commands. And nothing on the user-side should ever need pagination, I believe. Since admin-level commands really are only meant to be run in (Authorized) Netlify Functions, which run in a Node runtime, my library wouldn’t even work there. It’s running as expected!
Well, @AaronP , now I feel like it’s time for me to find a new career - my answer in the helpdesk was about 1% as awesome as @jonsully 's.
Anyway, thank you Jon for these details which I didn’t know (I’d advised an inferior workaround), and Aaron, do let us know how it goes in implementing!
Haha sorry Chris! I just spent a lot of time reading the GoTrue source while writing my library and had seen the question before! Just one of those things that I wish was documented a bit more But agreed, do let us know how it goes Aaron!
Wow @jonsully haha you’ve done it again - Amazing write up, interesting that I couldn’t find related posts or the docs for it after spending a considerable amount of time searching different things!
It has definitely fixed my issue, I thought there must be some pagination related thing going on but just didnt know what! The only thing is that I am at the moment requesting all the users at once since I am not receiving X-Total-Count response header.
Haha @fool Your advice would have also fixed my issues, don’t go finding a new career just yet Thanks for all of your time in looking up what I couldn’t find!!