refactor/significant-changes #3

Merged
mkelvers merged 71 commits from refactor/significant-changes into main 2026-05-14 11:25:25 +00:00
Showing only changes of commit 6f1b4db4f5 - Show all commits

View File

@@ -2,19 +2,34 @@ package middleware
import ( import (
"mal/internal/domain" "mal/internal/domain"
"net/http"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func AuthMiddleware(svc domain.AuthService) gin.HandlerFunc { func AuthMiddleware(svc domain.AuthService) gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
// Allow access to login and logout endpoints without authentication
if c.Request.URL.Path == "/login" || c.Request.URL.Path == "/logout" {
c.Next()
return
}
sessionID, err := c.Cookie("session_id") sessionID, err := c.Cookie("session_id")
if err == nil { if err != nil {
c.Redirect(http.StatusSeeOther, "/login")
c.Abort()
return
}
user, err := svc.ValidateSession(c.Request.Context(), sessionID) user, err := svc.ValidateSession(c.Request.Context(), sessionID)
if err == nil { if err != nil {
c.Redirect(http.StatusSeeOther, "/login")
c.Abort()
return
}
c.Set("User", user) c.Set("User", user)
}
}
c.Next() c.Next()
} }
} }