Multi-User Session Management
Learn how to implement multi-user session management in your Supervisely apps, ensuring isolated user interactions with widgets.
Introduction
In Supervisely SDK version 6.73.454, multi-user session management was introduced, allowing each user's interactions with app widgets to be isolated from others. This means that when one user interacts with a widget, it does not affect what other users see.
This is particularly useful for applications that can be used by a large number of users simultaneously, as it optimizes resource usage by avoiding the need to run separate app sessions for each user.
Enable Multi-User Mode
At the beginning of your app code, enable multi-user session management by calling:
sly.env.enable_multiuser_app_mode()This ensures that the app operates in a multi-user context.
Session-Specific Data Handling
Then, ensure that your callbacks and widget interactions are designed to work with session-specific data.
Avoid using global variables to store user-specific information, as this can lead to data leakage between sessions.
Instead of using global variables to store user-specific information (like filter states), retrieve user-specific data within the callbacks or use session-specific storage if available. This prevents data leakage between sessions.
Get Current User ID:
user_id = sly.env.user_from_multiuser_app()Get API Instance:
user_api = sly.app.session_user_api(). It provides an API instance scoped to the current user's permissions. So you can perform actions on behalf of the user.
For example:
Example Application
Here is a simple example of a multi-user app that generates a random number for each user when they press a button. Each user will see their own random number without affecting others.

Advanced Debugging in Multi-User Apps
When developing multi-user apps, you might want to test how the app behaves for different users. You can use the advanced debugging mode to simulate multiple users. Check the Advanced Debugging documentation for detailed instructions on setting up and using advanced debugging mode.
Recap
In this guide, we covered the basics of implementing multi-user session management in your Supervisely apps. By enabling multi-user mode and designing your app to handle session-specific data, you can create a more efficient and user-friendly experience for all users.
Last updated
Was this helpful?