Logout / Login and automatic routing

Hi,
I’m facing an issue when a user logs out of the application, its current route is somehow stored, and then, when he logs in again, instead of arriving on the welcome page of the app, he is redirected to it’s previous URL (before logout).
I played a bit with the custom request cache, but doesn’t seems to matter a lot…

Has someone an idea on how to force the login to the welcome page ?

Thanks,

What I do is, after successful login I do the following:

ui.navigate(DashboardView.class);

Where DashboardView (default view):

@Route(value="", layout = MainAppLayout.class)
@RouteAlias(value = "Dashboard", layout = MainAppLayout.class)

Although I do like the default use to continue to the previous path when i.e. the server has restarted for some reason.
So the question is how you do the logout.
In my case I do the logout like this:

		UI.getCurrent().getPage().executeJs("window.close();");
		UI.getCurrent().getPage().executeJs("window.location.href=''");
		
		VaadinSession.getCurrent().getSession().invalidate();

So technically it doesn’t hold the last location, since the last location is ‘’.
Although the way I do the logout I get a brief “Session invalidated” error message which I would like to have removed but haven’t figured out how to do it.

What is your logout implementation?

p.s. the window.close() is for when the application runs as a PWA on an Android and by logging out it also closes down the application (have really tested it though, but doesn’t hurt the Windows browsers!)

Hi,

My logout implementation looks like your, but I’m on Vaadin 19, so, a few differences still :

UI.getCurrent().getSession().close();
SecurityContextHolder.clearContext();	

I think the trick is to force the navigation to a specific route after login, but how do you achieve this ?
I’m using a custom login form and don’t really know how to catch this login event.

Thanks for your answer :slight_smile:

Ohh I see, you are using Spring Security, while I am using plain Vaadin J2EE (no spring everything custom/hand made!).
No idea about the login but I would try in your case the following at logout

		UI.getCurrent().getPage().executeJs("window.location.href=''");

or something like that in order to redirect to the first page and lose the location at the URL.

I am also using the URL to navigate to a specific view after login, perhaps you have a code snippet that does the same - search for something like:

Object intendedPath = VaadinSession.getCurrent().getAttribute("intendedPath");

in your code.

Sorry I can’t be of more help :slight_smile:

You gave me some good input there.

I’ll try to play around with all the parameters and post a solution here if I can get something working.

Thanks for your help.