StreamlitExtras icon indicating copy to clipboard operation
StreamlitExtras copied to clipboard

Setting a cookie doesn't work when expires_at is not set

Open mkosiedowski opened this issue 11 months ago • 0 comments

I found an issue with cookie_manager.set method. It seems that when the expires_at parameter is not set in your Python code, it doesn't actually default to 720 minutes (as stated in the documentation), but in fact - the cookie is not set at all. That's due to this line in the frontend code:

"expires": new Date(expires) || new Date(new Date().getTime() + defaultExpiryMinutes * 60000),

The expression new Date(expires) always returns a Date object, even when the expires value is false, undefined, 0, null or an empty string. That's why this expression never falls back to the default value.

I would suggest changing that line to something like:

"expires": expires ? new Date(expires) : new Date(new Date().getTime() + defaultExpiryMinutes * 60000),

Until this bug is fixed, let everyone know that you should set the expires_at in your Python code (and pay close attention to the timezone - like mentioned in the example in the docs)

mkosiedowski avatar Jan 24 '25 07:01 mkosiedowski