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- NodeJS
- GoLang
- Python
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 ThirdPartyEmailPassword
includeRecipeIds: ["thirdpartyemailpassword"],
})
users = usersResponse.users;
nextPaginationToken = usersResponse.nextPaginationToken;
}
import "github.com/supertokens/supertokens-golang/supertokens"
func main() {
// get the latest 100 users
result, err := supertokens.GetUsersNewestFirst(nil, nil, nil)
if err != nil {
// TODO: Handle error
return
}
// get the next 200 users
limit := 200
result, err = supertokens.GetUsersNewestFirst(result.NextPaginationToken, &limit, nil)
if err != nil {
// TODO: Handle error
return
}
// get for specific recipes
includeRecipeIds := []string{"thirdpartyemailpassword"}
result, err = supertokens.GetUsersNewestFirst(result.NextPaginationToken, &limit, &includeRecipeIds)
if err != nil {
// TODO: Handle error
return
}
}
- Asyncio
- Syncio
from supertokens_python.asyncio import get_users_newest_first
async def some_func():
# get the latest 100 users
users_response = await get_users_newest_first()
# get the next 200 users
users_response = await get_users_newest_first(200, users_response.next_pagination_token)
# get for specific recipes
users_response = await get_users_newest_first(
200,
users_response.next_pagination_token,
# only get for those users who signed up with ThirdPartyEmailPassword
["thirdpartyemailpassword"]
)
from supertokens_python.syncio import get_users_newest_first
# get the latest 100 users
users_response = get_users_newest_first()
# get the next 200 users
users_response = get_users_newest_first(200, users_response.next_pagination_token)
# get for specific recipes
users_response = get_users_newest_first(
200,
users_response.next_pagination_token,
# only get for those users who signed up with ThirdPartyEmailPassword
["thirdpartyemailpassword"]
)
#
Oldest First- NodeJS
- GoLang
- Python
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 ThirdPartyEmailPassword
includeRecipeIds: ["thirdpartyemailpassword"]
});
users = usersResponse.users;
nextPaginationToken = usersResponse.nextPaginationToken;
}
- If the
nextPaginationToken
isundefined
, then there are no more users to loop through. - If there are no users in your app, then
nextPaginationToken
will beundefined
andusers
will be an empty array - Each element in the
users
array is according to the output of the core API as shown here.
import "github.com/supertokens/supertokens-golang/supertokens"
func main() {
// get the oldest 100 users
result, err := supertokens.GetUsersOldestFirst(nil, nil, nil)
if err != nil {
// TODO: Handle error
return
}
// get the next oldest 200 users
limit := 200
result, err = supertokens.GetUsersOldestFirst(result.NextPaginationToken, &limit, nil)
if err != nil {
// TODO: Handle error
return
}
// get for specific recipes
includeRecipeIds := []string{"thirdpartyemailpassword"}
result, err = supertokens.GetUsersOldestFirst(result.NextPaginationToken, &limit, &includeRecipeIds)
if err != nil {
// TODO: Handle error
return
}
}
- If the
result.NextPaginationToken
isnil
, then there are no more users to loop through. - If there are no users in your app, then
result.NextPaginationToken
will benil
andresult.Users
will be an empty array - Each element in the
result.Users
array is according to the output of the core API as shown here.
- Asyncio
- Syncio
from supertokens_python.asyncio import get_users_oldest_first
async def some_func():
# get the latest 100 users
users_response = await get_users_oldest_first()
# get the next 200 users
users_response = await get_users_oldest_first(200, users_response.next_pagination_token)
# get for specific recipes
users_response = await get_users_oldest_first(
200,
users_response.next_pagination_token,
# only get for those users who signed up with ThirdPartyEmailPassword
["thirdpartyemailpassword"]
)
from supertokens_python.syncio import get_users_oldest_first
# get the latest 100 users
users_response = get_users_oldest_first()
# get the next 200 users
users_response = get_users_oldest_first(200, users_response.next_pagination_token)
# get for specific recipes
users_response = get_users_oldest_first(
200,
users_response.next_pagination_token,
# only get for those users who signed up with ThirdPartyEmailPassword
["thirdpartyemailpassword"]
)
#
Get the number of users in your app- NodeJS
- GoLang
- Python
import {getUserCount} from "supertokens-node";
async function getCount() {
let count = await getUserCount()
}
import (
"fmt"
"github.com/supertokens/supertokens-golang/supertokens"
)
func main() {
count, err := supertokens.GetUserCount(nil)
if err != nil {
// TODO: Handle error
return
}
fmt.Println(count)
}
- Asyncio
- Syncio
from supertokens_python.asyncio import get_user_count
async def some_func():
user_count = await get_user_count()
print(user_count) # TODO..
from supertokens_python.syncio import get_user_count
user_count = get_user_count()