From 9f62e09c88c1ef8b237ab5d7e4d8791fcf4fae8f Mon Sep 17 00:00:00 2001 From: T Date: Sat, 12 Jul 2025 15:23:48 -0600 Subject: Use / as the default auth cookie path. --- auth.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'auth.go') diff --git a/auth.go b/auth.go index ac1fc57..7e5de19 100644 --- a/auth.go +++ b/auth.go @@ -42,6 +42,13 @@ type AuthConfig[T any] struct { MaxAge time.Duration } +func (ac AuthConfig[T]) urlPath() string { + if ac.URLPath == "" { + return "/" + } + return ac.URLPath +} + // SerDes defines the interface for serializing and deserializing authentication data. // // Implementations must handle conversion between type T and byte streams. @@ -139,7 +146,7 @@ func (a Auth[T]) Set(w http.ResponseWriter, data T) error { cookie := &http.Cookie{ Name: a.config.CookieName, Value: a.enc.Encrypt(buf.Bytes()), - Path: a.config.URLPath, + Path: a.config.urlPath(), Domain: a.config.URLDomain, MaxAge: int(a.config.MaxAge / time.Second), Secure: a.config.HTTPSOnly, @@ -197,7 +204,7 @@ func (a Auth[T]) Clear(w http.ResponseWriter) { cookie := &http.Cookie{ Name: a.config.CookieName, Value: "", - Path: a.config.URLPath, + Path: a.config.urlPath(), Domain: a.config.URLDomain, MaxAge: -1, Secure: a.config.HTTPSOnly, -- cgit v1.2.3