NathanChen198 / streamlit-cookies-controller

Control client browser cookie for the site.
MIT License
31 stars 1 forks source link

It seems that a sleep function is necessary to synchronize browser cookies with Streamlit sessions #4

Open JeHwanYoo opened 3 months ago

JeHwanYoo commented 3 months ago

Hello,

I hope you're having a great day.

I have encountered an issue while using this library where the synchronization between browser cookies and the Streamlit session does not align properly.

Fortunately, I managed to workaround the issue with the following simple method:

def sync_cookie_to_session():
    cookie_controller.refresh() # sync
    time.sleep(1) # This brief pause is absolutely necessary. Without it, there is a high probability of failing to retrieve the browser's cookies.
    st.session_state['authentication_status'] = cookie_controller.get('authentication_status')
    st.session_state['username'] = cookie_controller.get('username')

However, this method does not guarantee success and does not seem ideal. Do you have any good ideas for polling until the browser's cookies are successfully retrieved? If you have any suggestions, please submit a PR or provide a hint and I will try to implement it.

Thank you.

ivan-schinella commented 3 months ago

when I invoke cookie_controller.refresh() I get a key duplication error...