Skip to Content
🎉 New release with new features and improvements! V0.0.2 Release →

User Service

The User Service provides methods for user management, profile updates, and user CRUD operations.

Methods

me

Retrieves the current authenticated user’s profile, this endpoint uses the JWT token to identify the user.

await bshEngine.users.me();

init

Initializes a new user account with profile data.

await bshEngine.users.init({ payload: { email: 'user@example.com', password: null, roles: ['DEV_USER'], profile: { firstName: 'John', lastName: 'Doe' } } });
PropertyTypeRequiredDescription
emailstringyesThe email address of the user
passwordstringnoThe password of the user. If null, the user will need to set it later
rolesstring[]yesThe roles assigned to the user
profileobjectyesUser profile data. This object is customizable; define any fields you want to include in a user’s profile

updateProfile

Updates the current user’s profile information.

await bshEngine.users.updateProfile({ payload: { firstName: 'Jane', lastName: 'Smith', phone: '+1234567890' } });
PropertyTypeRequiredDescription
payloadobjectyesPartial profile object containing the fields to update. Fields depend on your profile schema

updatePicture

Uploads and updates the current user’s profile picture.

const fileInput = document.querySelector('input[type="file"]'); const file = fileInput.files[0]; await bshEngine.users.updatePicture({ payload: file });
PropertyTypeRequiredDescription
payloadFileyesThe image file to upload as the profile picture

updatePassword

Updates the current user’s password.

await bshEngine.users.updatePassword({ payload: { currentPassword: 'old-password', newPassword: 'new-secure-password' } });
PropertyTypeRequiredDescription
currentPasswordstringyesThe user’s current password
newPasswordstringyesThe new password to set

getById

Retrieves a user by their ID.

await bshEngine.users.getById({ id: 'user-123' });
PropertyTypeRequiredDescription
idstringyesThe ID of the user to retrieve

Searches for users using the BSH Search object. Supports filtering, sorting, pagination, and grouping.

await bshEngine.users.search({ payload: { fields: ['userId', 'email', 'profile'], filters: [ { field: 'email', operator: 'ilike', value: 'john' } ], sort: [ { field: 'email', direction: 1 } ], pagination: { page: 0, size: 10 } } });
PropertyTypeRequiredDescription
payloadBshSearchyesThe search criteria. See BSH Search documentation for details

list

Lists users with optional query parameters for pagination, sorting, and filtering.

await bshEngine.users.list({ queryParams: { page: '0', size: '10', sort: 'email:asc', filter: 'status:eq:active' } });
PropertyTypeRequiredDescription
queryParamsobjectnoQuery parameters for listing users
queryParams.pagestringnoThe page number (default: 0)
queryParams.sizestringnoThe number of items per page (default: 10)
queryParams.sortstringnoSort by field and direction (format: field:direction)
queryParams.filterstringnoFilter conditions (format: field:operator:value, comma-separated for multiple filters)

update

Updates a user’s information. Requires userId in the payload.

await bshEngine.users.update({ payload: { userId: 'user-123', email: 'updated@example.com', profile: { firstName: 'Updated', lastName: 'Name' } } });
PropertyTypeRequiredDescription
payloadobjectyesPartial user object containing the fields to update. Must include userId

count

// Count all users await bshEngine.users.count({}); // Count filtered entities await bshEngine.users.count({ payload: { filters: [ { field: 'name', operator: 'eq', value: 'ApiKey 1' } ] } });

deleteById

Deletes a user by their ID.

await bshEngine.users.deleteById({ id: 'user-123' });
PropertyTypeRequiredDescription
idstringyesThe ID of the user to delete