summaryrefslogtreecommitdiff
path: root/pkg/web/cookie/reset.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/web/cookie/reset.go')
-rw-r--r--pkg/web/cookie/reset.go35
1 files changed, 12 insertions, 23 deletions
diff --git a/pkg/web/cookie/reset.go b/pkg/web/cookie/reset.go
index 87e815e..cfb1830 100644
--- a/pkg/web/cookie/reset.go
+++ b/pkg/web/cookie/reset.go
@@ -8,29 +8,18 @@ import (
)
func Reset(name string) *http.Cookie {
- return Clear(&http.Cookie{
- Name: name,
- })
+ return New(
+ name,
+ "",
+ WithExpiration(time.Unix(0, 0)),
+ WithPath("/"),
+ WithHttpOnly(true),
+ WithSecure(true),
+ WithSameSite(http.SameSiteDefaultMode),
+ WithDomain(env.Fetch("HOST", "localhost")),
+ )
}
-func Expire(w http.ResponseWriter, r *http.Request, name string) {
- cookie, err := r.Cookie(name)
- if err != nil {
- http.SetCookie(w, Reset(name))
- } else {
- Clear(cookie)
- http.SetCookie(w, cookie)
- }
-}
-
-func Clear(cookie *http.Cookie) *http.Cookie {
- cookie.Value = ""
- cookie.Expires = time.Unix(0, 0)
- cookie.MaxAge = -1
- cookie.Path = "/"
- cookie.HttpOnly = true
- cookie.Secure = true
- cookie.SameSite = http.SameSiteDefaultMode
- cookie.Domain = env.Fetch("HOST", "localhost")
- return cookie
+func Expire(w http.ResponseWriter, name string) {
+ http.SetCookie(w, Reset(name))
}