Extra-Streamlit-Components
Extra-Streamlit-Components copied to clipboard
CookieManager not finding cookies that are clearly available
The CookieManager does not appear to properly find cookies in some scenarios.
In the simplest scenario, I am executing the following code:
cookie_manager = stx.CookieManager(key="cookie_manager_" + str(time.time()))
session_id = cookie_manager.get(cookie="session_id")
print(cookie_manager.cookies)
The result of the print
operation is { }
, even when there are cookies set. And the session_id
is None
.
Looking at the browser's development panel, I can see my session cookie in there:
This seems to happen any time I refresh the page I'm on (hitting F5), OR when I navigate directly to a page where I am checking the session_id
(such as a protected page, where the user must be authenticated). This does not happen when just navigating around my multi-page app by clicking links.
I've tested this in Chrome and Firefox, and the same thing happens.
This is problematic, because I use the session cookie to store my user's session ID, and if streamlit can't find it, it sends them to the login page (when they're already logged in).
In my case i inserted a short time.sleep(0.3)
after setting the cookie and a while loop while getting. IDK why this is an issue but IMO CookieManager is huge pain in the ass and i'd not use it if i were not forced to use it ... :/
This, and a number of other things, has prompted me to rewrite my entire application in react.
The learning curve was a little steeper, and obviously it's more work than just writing Python code, but the results are so much better than what streamlit offers.
Streamlit is great for prototyping, but I would not use it in a production application.
I might be doing the same. Ditching streamlit altogether because authentication is just too experimental and buggy.