lovasoa / SQLpage

SQL-only webapp builder, empowering data analysts to build websites and applications quickly
https://sql.ophir.dev
MIT License
882 stars 62 forks source link

Anybody having trouble removing cookies? #368

Closed lovasoa closed 1 month ago

lovasoa commented 1 month ago

Discussed in https://github.com/lovasoa/SQLpage/discussions/361

Originally posted by **E8y2FqZE** May 31, 2024 I've made a "flash message" using the alert component that I want to show exactly once when someone successfully updates a resource. So for example if I set a cookie like this: ``` update users set name = :name, email = :email where id = :id; select 'cookie' as component, 'admin.alert.title' as name, 'User updated' as value; select 'redirect' as component, 'user.sql?user=' || :id as link; ``` This cookie is correctly set. ![image](https://github.com/lovasoa/SQLpage/assets/136404184/7edf05f8-90ca-4b98-a5d5-f5315570830d) And then in the page that it redirects to, I do this: ``` -- clear flash cookie select 'cookie' as component, 'admin.alert.title' as name, true as remove; --- display the value select 'alert' as component, sqlpage.cookie('admin.alert.title') as title, 'green' as color where sqlpage.cookie('admin.alert.title') is not null; ``` The alert is correctly displayed, and I can see that the HTTP headers are trying to unset the cookie in the response (expiration date is in the past): ![image](https://github.com/lovasoa/SQLpage/assets/136404184/04671411-a91c-40bd-8e8d-060d97c31793) Frustratingly, Firefox and Chrome are both hanging on to the cookie and thus I'm continuing to see the alert. I don't think this is a technical problem with SQLPage because it looks like the correct HTTP header is being sent to remove the cookie, but I just can't wrap my mind around why this isn't working. In desperation I tried this, which *does* work. ``` select 'cookie' as component, 'admin.alert.title' as name, unixepoch() as expires, '' as value; ``` My computer clock is correct, so I am baffled at why `true as remove` doesn't work...