I’m building a micro-frontend setup using Flutter web where I have two different apps running on the same domain but different paths.
My Setup:
- Authentication app at
/auth/ - Dashboard app at
/dashboard/
Both applications are built separately and hosted on different routes. Here’s what should happen:
- User logs in through the auth app and gets redirected to dashboard.
- When user clicks logout in dashboard, it should clear all data and go back to auth.
- Browser back button shouldn’t allow returning to dashboard after logout.
Current Implementation:
For login redirect:
import 'dart:js' as javascript;
void navigateToDashboard() {
javascript.context.callMethod('eval', [
'window.location.replace("/dashboard/")'
]);
}
For logout:
import 'dart:html' as browser;
import 'dart:js' as javascript;
void performLogout() {
browser.window.sessionStorage.clear();
browser.window.localStorage.clear();
javascript.context.callMethod('eval', [
'window.location.replace("/auth/")'
]);
}
What I’ve Attempted:
- Using
browser.window.location.assign() - Trying
browser.window.open()with_selftarget - Standard Flutter navigation with
Navigator.push() - Custom
popstateevent handling - Different routing libraries like
go_router
The Issue:
After logout and redirect, users can still hit the back button and access the dashboard app even though their session is cleared. This creates security concerns since they can view the protected content momentarily.
What I’m Looking For:
- Best practices for navigating between independent Flutter web apps.
- Ways to properly clear browser history after logout.
- Methods to detect and handle back navigation in this scenario.
Has anyone dealt with similar multi-app Flutter web deployments? Any suggestions would be helpful!