You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Oh yes. Great you bring it up. That one also bit me once, but I have not documented it before. Here is what happens:
the SessionMiddleware provides the "session" property to the request before entering your page creator
after the page is created (eg. when the function is complete) the SessionMiddleware grabs the session property and encodes the data into the response to the browser
modifying the session property on button click happens after the response is already send; so it can not update the browser cookie anymore
You see, it's totally logical :-) But when working with NiceGUI you expect every state to be magically synced to the client. Unfortunately here you are not using any NiceGUI functionality but rather the underlying SessionMiddleware which does not know about the websocket ...
I just added a note to the authentication demo code which also references this issue:
Hi!
I might be missing something, but for some reason, session is not preserved if I modify it inside the button callback.
This code shows "Storing" message in console, but
token
value is not preserved.If I move session modification to the page function, everything works.
The text was updated successfully, but these errors were encountered: