Login and Logout in vaadin 8

Hi guys,

My name is Harrison and I am new to Vaadin. I am here to ask for some advices. Thanks so much in advance.

I am now trying to create a login function in Vaadin. When login, I just pass the username as a parameter in navigateTo() method to a dashboard view, like this:

getUI().getNavigator().navigateTo(DashBoard.NAME + "/" + email.getValue()); and then the dashboard view gets the parameter. I guess this is not a real login, right? And the result of this “ugly login” is that, when I logout, I am using these code:

logout.addClickListener(e -> { getUI().getSession().close(); getUI().getNavigator().navigateTo(LoginForm.NAME); }); It will redirect to LoginFrom view and if I click the “back” button on browser, it will show session expired. BUT if I click refresh at that time, the page will go back to the dashboard view with the username parameter, which means it becomes “logged in” again. I hope this make sense.

So my question is. what is a correct login mechanism when using Vaadin 8. Or if anyone has created a similar login app and willing to share to me for me to learn, i really really appreciate that.

Also, I wonder what is a best way to create a forgot/reset password function. The app will send a link to email, and after click the link, the user will be direct to a view based on the parameter on that link. This is easy to be done when using javaee servlet, but I dont know the vaadin way. Thanks so so much. Thanks in advance.


Maybe you can take a look at our bakery app?

The “Session expired” message is caused by the underlying session being closed. The Navigator is associated with a Vaadin UI and the UI needs a open session to work. After you close the session, a new UI must be created. UI is created when your UI class init method is called. To make the browser init a new UI instance use

Page.setLocation() to redirect the user back to the login page instead of the Navigator.

More details here:


Typically after a successful login the user name is store into the session, not just used as a navigator parameter. Navigator parameters are after all something the user of the application can easily manipulate via the address bar of the browser.

Here’s a minimal example how to handle login & logout:

See the full sample on vaadinfiddle.com