Redirecting on Session Timeout

Hi,

I am using a ThymeLeaf login page for my Vaadin App.
Login is handled with spring security,

@Bean
	public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

		http.authorizeHttpRequests(
				auth -> auth.requestMatchers("/login", "/css/**").permitAll().anyRequest().authenticated())
				.formLogin(form -> form.loginPage("/login").loginProcessingUrl("/process-login")
						.defaultSuccessUrl("/home", true).failureUrl("/login?error=true").permitAll())
				.logout(logout -> logout.logoutUrl("/logout").logoutSuccessUrl("/login?logout=true").permitAll())
				.csrf(csrf -> csrf.disable());

		http.sessionManagement(session -> session.invalidSessionUrl("/login?timedOut"));

		return http.build();
	}

and timeout

![invalidJSON|690x52](upload://q83JOUElGfQO1HFPpWGHkR9WJws.png)
server.servlet.session.timeout=10m

After the session expires (as per the session.timeout setting),we see a banner with the message:

“Invalid JSON from server:” followed by the HTML source of the login page.

and on clicking that the redirect to login page happens.

Ideally, when the session expires, I want to display a custom session expired message or redirect to the login page rather than showing the “Invalid JSON” banner.

How can I achieve this?

Take a look at: How to modify the bootstrap page in Vaadin

Forcing a Page Reload After an Invalid Server Response
If the XHR response can’t be parsed as JSON, Vaadin looks for a “Vaadin-Refresh” string anywhere inside the response text. If it’s present, Vaadin reloads the page instead of showing an error message. Usually such responses are served by some 3rd party servers and then you need to add the refresh token as a meta tag to the HTML page served by it.

Based on the docs my understanding is adding

<meta name="refresh" content="Vaadin-Refresh">

should trigger the page reload in the event of an invalid response. However, it doesn’t seem to resolve the issue on my end.

Are you sure you have applied it correctly? Does your Notification’s content change / is the refresh information in there?

Yes the refresh meta tag is also shown.

Then I would suggest to create a bug report.

Something missing from the documentation is that you can tell Vaadin which url to go to.
We have this in the login page html from our Vaadin7 days:

<!-- This tells Vaadin to load "/ptsmc/app" if the server responds to an ajax request with this page (when user session is no longer valid): -->
<!-- Vaadin-Refresh:/ptsmc/app -->
1 Like

Adding the space after the Vaadin-Refresh token fixes the issue.
(e.g. <meta name="refresh" content="Vaadin-Refresh "> )