Skip to content

Users service

consortium.server.services.users_service

UsersService(events_service)

get_user_by_user_id(user_id)

Returns a currently logged-in user by their user ID.

Parameters:

Name Type Description Default
user_id str | UUID

The ID of the user to retrieve.

required

Returns:

Type Description
User

The user with the specified ID.

Raises:

Type Description
UserIDNotFoundError

If no logged-in user with the given ID exists.

get_user_by_access_token(access_token)

Returns a currently logged-in user by their access token.

Parameters:

Name Type Description Default
access_token str

The JWT subject string used as the access token.

required

Returns:

Type Description
User

The user whose access token matches.

Raises:

Type Description
UserAccessTokenNotFoundError

If no logged-in user has the given access token.

get_all_users()

Returns all currently logged-in users.

Returns:

Type Description
list[User]

A list of all active user sessions. Empty if no users are logged in.

update_user_display_name_by_user_id(display_name, user_id)

Updates the display name of a logged-in user.

Parameters:

Name Type Description Default
display_name str

The new display name to set.

required
user_id str | UUID

The ID of the user to update.

required

Returns:

Type Description
User

The updated user.

Raises:

Type Description
UserIDNotFoundError

If no logged-in user with the given ID exists.

login_user(username, password)

Authenticates a user account and creates an active user session.

Emits a USER_LOGGED_IN event after successful login.

Parameters:

Name Type Description Default
username str

The username of the account to authenticate.

required
password str

The password of the account to authenticate.

required

Returns:

Type Description
User

The newly created user session.

Raises:

Type Description
UserAccountAuthenticationError

If no account with the given username exists, or if the password does not match.

logout_user_by_user_id(user_id)

Ends a user session and removes it from the active users registry.

Emits a USER_LOGGED_OUT event after successful logout.

Parameters:

Name Type Description Default
user_id str | UUID

The ID of the user session to end.

required

Raises:

Type Description
UserIDNotFoundError

If no logged-in user with the given ID exists.