Skip to main content

If you are using our backend SDK that is lesser than the following versions, please visit the older documentation link here.

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({
tenantId: "public"
});

let users = usersResponse.users;
let nextPaginationToken = usersResponse.nextPaginationToken;

// get the next 200 users
usersResponse = await getUsersNewestFirst({
tenantId: "public",
limit: 200,
paginationToken: nextPaginationToken,
})

users = usersResponse.users;
nextPaginationToken = usersResponse.nextPaginationToken;

// get for specific recipes
usersResponse = await getUsersNewestFirst({
tenantId: "public",
limit: 200,
paginationToken: nextPaginationToken,
// only get for those users who signed up with ThirdPartyEmailPassword
includeRecipeIds: ["thirdpartyemailpassword"],
})

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({
tenantId: "public"
});
let users = usersResponse.users;
let nextPaginationToken = usersResponse.nextPaginationToken;

// get the next oldest 200 users
usersResponse = await getUsersOldestFirst({
tenantId: "public",
limit: 200,
paginationToken: nextPaginationToken,
});

users = usersResponse.users;
nextPaginationToken = usersResponse.nextPaginationToken;

// get for specific recipes
usersResponse = await getUsersOldestFirst({
tenantId: "public",
limit: 200,
paginationToken: nextPaginationToken,
// only get for those users who signed up with ThirdPartyEmailPassword
includeRecipeIds: ["thirdpartyemailpassword"]
});

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.
Multi Tenancy

Notice that we pass in the tenantId as "public". This means that the functions above will loop through the users of the public tenantId. If you want to loop through other tenant IDs, you can pass in the tenant ID string to the function call.

This also implies that there is no way to loop through all users across all tenants in one go. If you want to do this, you will have to loop through each tenant one by one.

Get the number of users in your app#

import {getUserCount} from "supertokens-node";

async function getCount() {
let count = await getUserCount()
}
Multi Tenancy

By default, the getUserCount function will return the number of users across all tenants. If you want to get the number of users for a specific tenant, you can pass in the tenant ID string to the function call.

Looking for older versions of the documentation?
Which UI do you use?
Custom UI
Pre built UI