Skip to main content

User Pagination

Loop through users in your app#

Newest First#

let {getUsersNewestFirst} = require("supertokens-node/recipe/emailpassword");
// get the latest 100 userslet {users, nextPaginationToken} = await getUsersNewestFirst();
// get the next 200 userslet {users, nextPaginationToken} = await getUsersNewestFirst(200, nextPaginationToken);

Oldest First#

let {getUsersOldestFirst} = require("supertokens-node/recipe/emailpassword");
// get the oldest 100 userslet {users, nextPaginationToken} = await getUsersOldestFirst();
// get the next 200 userslet {users, nextPaginationToken} = await getUsersOldestFirst(200, nextPaginationToken);
info
  • If the nextPaginationToken is undefined, then there are no more users to loop through.
  • If there are no users in your app, then nextPaginationToken will be undefined and users will be an empty array
  • Each element in the users array is of the form as mentioned here.

Get the number of users in your app#

let {getUserCount} = require("supertokens-node/recipe/emailpassword");
let count = await getUserCount()
caution

This runs an aggrigate query, and if you have millions of users, it may perform slowly.