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
					
				
					 1 changed files with 19 additions and 1 deletions
				
			
		|  | @ -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? | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lance Edgar
						Lance Edgar