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#

import { getUsersNewestFirst } from "supertokens-node";
async function getUsers() {    // get the latest 100 users    let usersResponse = await getUsersNewestFirst();
    let users = usersResponse.users;    let nextPaginationToken = usersResponse.nextPaginationToken;
    // get the next 200 users    usersResponse = await getUsersNewestFirst({        limit: 200,        paginationToken: nextPaginationToken,    })
    users = usersResponse.users;    nextPaginationToken = usersResponse.nextPaginationToken;
    // get for specific recipes    usersResponse = await getUsersNewestFirst({        limit: 200,        paginationToken: nextPaginationToken,        // only get for those users who signed up with ThirdPartyPasswordless        includeRecipeIds: ["thirdpartypasswordless"],    })
    users = usersResponse.users;    nextPaginationToken = usersResponse.nextPaginationToken;}

Oldest First#

import { getUsersOldestFirst } from "supertokens-node";
async function getUsers() {    // get the latest 100 users    let usersResponse = await getUsersOldestFirst();    let users = usersResponse.users;    let nextPaginationToken = usersResponse.nextPaginationToken;
    // get the next oldest 200 users    usersResponse = await getUsersOldestFirst({        limit: 200,        paginationToken: nextPaginationToken,    });
    users = usersResponse.users;    nextPaginationToken = usersResponse.nextPaginationToken;
    // get for specific recipes    usersResponse = await getUsersOldestFirst({        limit: 200,        paginationToken: nextPaginationToken,        // only get for those users who signed up with ThirdPartyPasswordless        includeRecipeIds: ["thirdpartypasswordless"]    });
    users = usersResponse.users;    nextPaginationToken = usersResponse.nextPaginationToken;}
  • 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#

import {getUserCount} from "supertokens-node";
async function getCount() {    let count = await getUserCount()}
Which frontend SDK do you use?
supertokens-web-js / mobile
supertokens-auth-react