Browse Source

better error message when storage_secret is missing

Rodja Trappe 1 year ago
parent
commit
5cfb662b2d
2 changed files with 7 additions and 3 deletions
  1. 1 0
      examples/authentication/main.py
  2. 6 3
      nicegui/storage.py

+ 1 - 0
examples/authentication/main.py

@@ -63,6 +63,7 @@ def login() -> Optional[RedirectResponse]:
         username = ui.input('Username').on('keydown.enter', try_login)
         password = ui.input('Password', password=True, password_toggle_button=True).on('keydown.enter', try_login)
         ui.button('Log in', on_click=try_login)
+    return None
 
 
 ui.run(storage_secret='THIS_NEEDS_TO_BE_CHANGED')

+ 6 - 3
nicegui/storage.py

@@ -128,9 +128,12 @@ class Storage:
         """
         request: Optional[Request] = request_contextvar.get()
         if request is None:
-            if context.get_client().is_auto_index_client:
-                raise RuntimeError('app.storage.user can only be used with page builder functions '
-                                   '(https://nicegui.io/documentation/page)')
+            try:
+                if context.get_client().is_auto_index_client:
+                    raise RuntimeError('app.storage.user can only be used with page builder functions '
+                                       '(https://nicegui.io/documentation/page)')
+            except RuntimeError:
+                pass  # no storage_secret (see #2438)
             raise RuntimeError('app.storage.user needs a storage_secret passed in ui.run()')
         session_id = request.session['id']
         if session_id not in self._users: