How to show custom session expired dialog in Jmix (similar to CUBA)?

Hello Jmix team!
In CUBA applications, when the user’s session expires (for example, when the same user logs in from another browser), a notification dialog is shown automatically:

  • It displays a message like “Session has expired. Please log in again.”
  • It has an OK button that redirects the user back to the login page.

In Jmix (Vaadin Flow), by default, when the session expires, I see a technical message like:
image

I want to implement the same behavior as in CUBA:

  • Show a user-friendly dialog
  • Provide an OK button that redirects the user to /login.

I use Jmix v.2.6.1

Hello!

Vaadin provides a mechanism to customize session expired messages: How to customize system messages in Vaadin.

Example from Vaadin docs:

@Component
public class CustomInitServiceListener implements VaadinServiceInitListener {
    @Override
    public void serviceInit(ServiceInitEvent event) {
        event.getSource().setSystemMessagesProvider(new SystemMessagesProvider() {
            @Override
            public SystemMessages getSystemMessages(SystemMessagesInfo systemMessagesInfo) {
                CustomizedSystemMessages messages = new CustomizedSystemMessages();
                messages.setSessionExpiredCaption("Session expired");
                messages.setSessionExpiredMessage("Take note of any unsaved data, and click here or press ESC key to continue.");
                messages.setSessionExpiredURL("login");
                messages.setSessionExpiredNotificationEnabled(true);
                return messages;
            }
        });
    };
}

To customize visual representation of notification use .v-system-error selector.

Thank you very much for your help! The solution worked perfectly in my project.

Hi again,

Thanks for the previous suggestions. I have a follow-up question regarding the “Session Expired” notification:

Currently, the notification appears even if the user manually logs out from their own browser, which I don’t want.

My requirements are:

  • The notification should appear only if another browser/session logs in.
  • Specifically, it should trigger only when there are 2 active users (or sessions) at the same time.
  • It should not appear if the user logs out from their own browser.

How can I implement this behavior in Jmix? Is there a way to track multiple active sessions per user and distinguish between self-logout and “logged in from another browser”?