Mohamed-512 / Extra-Streamlit-Components

An all in one place, to find complex or just not available components by default on streamlit.
Apache License 2.0
466 stars 59 forks source link

CookieManager not finding cookies that are clearly available #66

Open aronweiler opened 5 months ago

aronweiler commented 5 months ago

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: image

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).

gniewus commented 4 months ago

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 ... :/

aronweiler commented 4 months ago

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.

gabrielziegler3 commented 1 month ago

I might be doing the same. Ditching streamlit altogether because authentication is just too experimental and buggy.