I have two Flutter web applications running on the same server but as separate deployments. One handles authentication and the other is the main dashboard. The auth app runs on one path and the main app runs on another path.
My current setup works like this - users log in through the first app, then get sent to the second app after successful authentication. When they want to log out from the main app, I clear their session data and send them back to the login app.
Here’s what I’m using for navigation between apps:
// For login success redirect
js.context.callMethod('eval', [
'window.location.replace("http://myserver.com:3000/dashboard/")'
]);
// For logout redirect
html.window.sessionStorage.clear();
html.window.localStorage.clear();
js.context.callMethod('eval', [
'window.location.replace("http://myserver.com:3000/auth/")'
]);
I’ve also experimented with different approaches like html.window.location.href
, html.window.location.replace()
, and even tried window.open()
with _self
parameter. I also looked into Flutter routing solutions like Navigator.pushNamed
and GoRouter
but those don’t seem to work across separate applications.
The main issue I’m facing is that after logout, users can still press the browser back button and return to the main app even though their session is cleared. This creates a security issue because they can see the previous state of the app.
What’s the best way to handle this kind of cross-app navigation in Flutter web? I need to either disable the back button functionality or detect when users try to go back and force them to the login page if their session is invalid.
Any suggestions for handling this micro-frontend architecture properly would be helpful.