User List
Get a paginated list of all users in the system.
Definition
await zkdb
.db(databaseName: string)
.userList(offset?: number): Promise<TUserFindResponse>;
Parameters
offset
(number, optional): Starting position for pagination. Defaults to 0.
Returns
Promise<TUserFindResponse>
: Returns a paginated list of all registered users in the system with their basic profile information (excluding sensitive data like private keys). This includes usernames, email addresses, public keys, and activation status. Useful for user management, directory services, and permission assignment.
type TUserFindResponse = {
data: TUserInfo[];
total: number;
limit: number;
offset: number;
};
type TUserInfo = {
userName: string;
email: string;
publicKey: string;
activated: boolean;
};
Example
import { ZkDatabase } from 'zkdb';
const zkdb = await ZkDatabase.connect({
userName: "chiro-user",
privateKey: "EKFTciRxyxshZjimay9sktsn7v5PvmC5zPq7q4JnitHUytxUVnFP",
environment: "node",
// This URL is for test environment
url: "https://api.zkdatabase.org/graphql",
});
await zkdb.auth.signIn();
const dbTest = zkdb.db('zkdb_test');
// Get first page of users
const users = await dbTest.userList();
console.log('Users found:', {
total: users.total,
count: users.data.length,
users: users.data.map(u => ({
name: u.userName,
email: u.email,
active: u.activated
}))
});
// Get next page
const nextPage = await dbTest.userList(100);
console.log('Next page:', nextPage.data.length, 'users');
await zkdb.auth.signOut();
Result:
Users found: {
"total": 156,
"count": 100,
"users": [
{
"name": "alice-dev",
"email": "[email protected]",
"active": true
},
{
"name": "bob-tester",
"email": "[email protected]",
"active": true
}
]
}
Next page: 56 users
Pagination:
- Default limit: 100 users per page
- Use
offset
parameter to get subsequent pages total
field shows total number of users available
Related: getUser()
| User Groups