use last cookie matching

master v0.3.0
Bel LaPointe 2022-02-18 11:02:00 -07:00
parent 4657dd9505
commit 99f88d2fb8
1 changed files with 8 additions and 3 deletions

View File

@ -183,9 +183,14 @@ func requestLoginCookie(r *http.Request) (User, bool) {
}
func getCookie(key string, r *http.Request) (string, bool) {
cookie, err := r.Cookie(key)
if err != nil {
log.Printf("err getting cookie %s: %v: %+v", key, err, r.Cookies())
var cookie *http.Cookie
cookies := r.Cookies()
for i := range cookies {
if cookies[i].Name == key && (cookies[i].Expires.IsZero() || time.Now().Before(cookies[i].Expires)) {
cookie = cookies[i]
}
}
if cookie == nil {
return "", false
}
return cookie.Value, cookie.Expires.IsZero() || time.Now().Before(cookie.Expires)