ktosiek / streamlit-cookies-manager

Access and change cookies from your Streamlit script
41 stars 29 forks source link

Not able to delete a cookie. #1

Open aegeavaz-pfizer opened 2 years ago

aegeavaz-pfizer commented 2 years ago

Hi ktosiek...

I'm testing your cookie manager, and looks good, but I'm not able to delete a cookie...

I have tried:

del cookies[name] cookies.delitem(name)

call save after this... and any combination works...

is there any way to delete an existing cookie?

Thank you very much.

zealpatel1990 commented 1 year ago

Yes please, liked this library better then stx. only missing is delete functionality.

Odrec commented 5 months ago

i have the same problem


# This should be on top of your script
cookies = EncryptedCookieManager(
    # This prefix will get added to all your cookie names.
    # This way you can run your app on Streamlit Cloud without cookie name clashes with other apps.
    prefix="ktosiek/streamlit-cookies-manager/",
    # You should really setup a long COOKIES_PASSWORD secret if you're running on Streamlit Cloud.
    password=os.environ.get("COOKIES_PASSWORD"),
)

if not cookies.ready():
    # Wait for the component to load and send us current cookies.
    st.spinner()
    st.stop()

print(cookies.pop("session"))
cookies.__delitem__("session")

I tried both and it doesn't work. Any ideas how to fix this?

SajjadAemmi commented 2 months ago

@Odrec You can try this:

# unset username in cookies
cookies['username'] = ""

and then:

if "username" in cookies.keys() and str(cookies['username']):
    # my coockies has username
else:
    # my coockies hasn't username