Fix main routing between /login and /pos
should only show one or the other depending on user login status
This commit is contained in:
parent
d52f0b3207
commit
bdae602289
|
@ -91,12 +91,30 @@ def main(page: ft.Page):
|
||||||
|
|
||||||
# cf .https://flet.dev/docs/guides/python/navigation-and-routing#building-views-on-route-change
|
# 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()
|
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':
|
if page.route == '/pos':
|
||||||
page.views.append(POSView(config, '/pos'))
|
page.views.append(POSView(config, '/pos'))
|
||||||
|
|
||||||
elif page.route == '/login':
|
elif page.route == '/login':
|
||||||
page.views.append(LoginView(config, '/login'))
|
page.views.append(LoginView(config, '/login'))
|
||||||
|
|
||||||
page.update()
|
page.update()
|
||||||
|
|
||||||
# TODO: this was in example docs but not sure what it's for?
|
# TODO: this was in example docs but not sure what it's for?
|
||||||
|
|
Loading…
Reference in a new issue