Chore: solved some todos

This commit is contained in:
Grail Finder
2025-06-12 07:04:20 +03:00
parent 6934b724ae
commit 74b10b8395
10 changed files with 50 additions and 82 deletions

View File

@ -26,9 +26,7 @@ func LogRequests(next http.Handler) http.Handler {
func GetSession(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// TODO: move
cookieName := "session_token"
sessionCookie, err := r.Cookie(cookieName)
sessionCookie, err := r.Cookie(models.AuthCookie)
if err != nil {
msg := "auth failed; failed to get session token from cookies"
log.Debug(msg, "error", err)
@ -54,7 +52,7 @@ func GetSession(next http.Handler) http.Handler {
sessionToken := cookieValue[sha256.Size:]
//verify signature
mac := hmac.New(sha256.New, []byte(cfg.CookieSecret))
mac.Write([]byte(cookieName))
mac.Write([]byte(models.AuthCookie))
mac.Write([]byte(sessionToken))
expectedSignature := mac.Sum(nil)
if !hmac.Equal([]byte(signature), expectedSignature) {