Forcing Login On Start

Hello!, I am sure this is an easy thing for everyone but I am confused and new. How do you force a login page when a user comes to the site?

I have been looking at the sample app and kind of figuring out how to handle the login but not were the page is being controlled from.

Thank you!

There are couple of ways how to do this. What is correct answer for you depends whether you are already using security framework, like Spring Security in your app or not. If you use such, then it is recommended to implement this at that level.

This is explained as part of this tutorial series https://vaadin.com/learn/tutorials/securing-your-app-with-spring-security

However if you are using vanilla Vaadin, then one approach is to implement BeforeEnterObserver interface in your MainLayou and do something like (naturally you need to implement notLoggedIn() condition specific to your app):

@Override
public void beforeEnter(BeforeEnterEvent event) {
    if (notLoggedIn()) {
	    event.rerouteTo("login");
    }
	...
}

Thank you!!! I had to call BeforeEnterObserver with and everything worked great!!

Do you just store the user as a variable then?

Typically, you would use a session attribute to store the information about the login.