diff options
Diffstat (limited to 'internal/auth/cookie.go')
| -rw-r--r-- | internal/auth/cookie.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/internal/auth/cookie.go b/internal/auth/cookie.go new file mode 100644 index 0000000..9fd6b6e --- /dev/null +++ b/internal/auth/cookie.go @@ -0,0 +1,23 @@ +package auth + +import ( + "net/http" + "time" +) + +const CookieName = "session" + +func SetSessionCookie(w http.ResponseWriter, token string) { + http.SetCookie(w, &http.Cookie{ + Name: CookieName, + Value: token, + Path: "/", + HttpOnly: true, + SameSite: http.SameSiteLaxMode, + MaxAge: int(SessionTTL / time.Second), + }) +} + +func ClearSessionCookie(w http.ResponseWriter) { + http.SetCookie(w, &http.Cookie{Name: CookieName, Value: "", Path: "/", HttpOnly: true, MaxAge: -1}) +} |
