Ben
Ben

Reputation: 336

Redirect after login to a view

I have implemented a Vaadin (23) app using Spring Boot (2.6). To access the app, users need to be logged in. To manage the login flow, I use the LoginForm of Vaadin. How can I redirect authenticated users to a defined view after login?

Upvotes: 1

Views: 2453

Answers (3)

kukis
kukis

Reputation: 4644

I had the same doubt. I ended up adding login listener and redirecting user manually. Works like a charm.

 LoginForm login = new LoginForm();
 login.setAction("login");
 login.addLoginListener(l -> UI.getCurrent().navigate("/home"));

Upvotes: 1

Peter
Peter

Reputation: 66

I managed to get this done by adding it to the WebSecurity (defaultSuccessUrl):

http.formLogin()
                .loginPage((LOGIN_URL)).permitAll()
                .loginProcessingUrl(LOGIN_URL)
                .defaultSuccessUrl("/dashboard")
                .failureUrl(LOGIN_ERROR);

After login the user gets redirect to the Page /dashboard

Upvotes: 1

Tatu Lund
Tatu Lund

Reputation: 10643

I would recommend you to download starter app via https://start.vaadin.com/ select few views to app with different access levels etc. This application will use VaadinWebSecurity / VaadinWebSecurityConfigurerAdapter that extends the regular Spring Security conf. It will use request cache to store original request and use stored path after login to redirect to view (the mechanism is built-in this helper class and you do not need to implement yourself). See also the documentation:

https://vaadin.com/docs/latest/security/enabling-security

Upvotes: 0

Related Questions