diff --git a/wuttapos/app.py b/wuttapos/app.py index ea6c5c7..eae304b 100644 --- a/wuttapos/app.py +++ b/wuttapos/app.py @@ -91,12 +91,30 @@ def main(page: ft.Page): # cf .https://flet.dev/docs/guides/python/navigation-and-routing#building-views-on-route-change - def route_change(route): + def route_change(e): page.views.clear() + + redirect = None + user_uuid = page.session.get('user_uuid') + if page.route == '/login' and user_uuid: + redirect = '/pos' + other = '/pos' + elif page.route == '/pos' and not user_uuid: + redirect = '/login' + other = '/login' + else: + redirect = '/pos' if user_uuid else '/login' + + if redirect and page.route != redirect: + page.go(other) + return + if page.route == '/pos': page.views.append(POSView(config, '/pos')) + elif page.route == '/login': page.views.append(LoginView(config, '/login')) + page.update() # TODO: this was in example docs but not sure what it's for?