aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/auth/middleware.go
diff options
context:
space:
mode:
Diffstat (limited to 'backend/auth/middleware.go')
-rw-r--r--backend/auth/middleware.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/backend/auth/middleware.go b/backend/auth/middleware.go
new file mode 100644
index 0000000..aca1648
--- /dev/null
+++ b/backend/auth/middleware.go
@@ -0,0 +1,24 @@
+package auth
+
+import (
+ "github.com/labstack/echo/v4"
+ appcontext "undef.ninja/x/feedaka/context"
+)
+
+// SessionAuthMiddleware validates session and adds user info to context
+func SessionAuthMiddleware(sessionConfig *SessionConfig) echo.MiddlewareFunc {
+ return func(next echo.HandlerFunc) echo.HandlerFunc {
+ return func(c echo.Context) error {
+ // Try to get user ID from session
+ userID, err := sessionConfig.GetUserID(c)
+ if err == nil {
+ // Add user ID to context
+ ctx := appcontext.SetUserID(c.Request().Context(), userID)
+ c.SetRequest(c.Request().WithContext(ctx))
+ }
+ // If no valid session, continue without authentication
+
+ return next(c)
+ }
+ }
+}