Skip to main content

User Pagination and Count

important

This is applicable for supertokens core version >= 3.5. For older core versions, please visit your backend SDK's reference docs.

This feature allows you to loop through (on your backend) all the users in your app. It also allows you to get the number of users.

Loop through users in your app#

Newest First#

let {getUsersNewestFirst} = require("supertokens-node");
// get the latest 100 userslet {users, nextPaginationToken} = await getUsersNewestFirst();
// get the next 200 userslet {users, nextPaginationToken} = await Supertokens.getUsersNewestFirst({    limit: 200,    paginationToken: nextPaginationToken,});
// get for specific recipeslet {users, nextPaginationToken} = await Supertokens.getUsersNewestFirst({    limit: 200,    paginationToken: nextPaginationToken,    // only get for those users who signed up with email and password    includeRecipeIds: ["emailpassword"]});

Oldest First#

let {getUsersOldestFirst} = require("supertokens-node");
// get the latest 100 userslet {users, nextPaginationToken} = await getUsersOldestFirst();
// get the next oldest 200 userslet {users, nextPaginationToken} = await Supertokens.getUsersOldestFirst({    limit: 200,    paginationToken: nextPaginationToken,});
// get for specific recipeslet {users, nextPaginationToken} = await Supertokens.getUsersOldestFirst({    limit: 200,    paginationToken: nextPaginationToken,    // only get for those users who signed up with email and password    includeRecipeIds: ["emailpassword"]});
  • 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 according to the output of the core API as shown here.

Get the number of users in your app#

let {getUserCount} = require("supertokens-node");
let count = await getUserCount()