From bdae6022899677494f0b73eb3f54fb06821d2bdf Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 26 Sep 2023 10:44:53 -0500 Subject: [PATCH] Fix main routing between /login and /pos should only show one or the other depending on user login status --- wuttapos/app.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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?