Redirecting the user to the login screen at the end of the session

How, instead of displaying in the browser “Pay attention to any unsaved data, and click here to continue”, to automatically redirect the user to the login screen after the expiration of the HTTP session lifetime?

1 Like

Hello Alex!

You should override AppUI class and its method close() that is ivoked when session is expired or explicitly invoked.

  1. MyAppAUI
public class MyAppUI extends AppUI {

    @Autowired(required = false)
    protected ServletContext servletContext;

    @Override
    public void close() {
        super.close();

        // Getting path to navigate
        String contextPath = servletContext == null ? null : servletContext.getContextPath();
        String logoutPath = Strings.isNullOrEmpty(contextPath) ? "/logout" : contextPath + "/logout";

        // Navigate
        AppUI.getCurrent().getPage().setLocation(logoutPath);
    }
}
  1. Register it in application configuration class:
@Bean("my_AppUI")
@UIScope
@Primary
public AppUI appUi() {
    return new MyAppUI();
}
  1. And exclude AppUI bean from context in application.properties:
jmix.core.exclude-beans=appUI
2 Likes

image

it does not work, as before, instead of the authorization window, here is a message

How did you test session expiration? For instance, I’ve set in application.properties:

jmix.ui.http-session-expiration-timeout-sec=15

And it works.

jmix.ui.http-session-expiration-timeout-sec=10

thanks , everything worked !