diff --git a/lib/user.go b/lib/user.go index e70aacd..4a2e478 100644 --- a/lib/user.go +++ b/lib/user.go @@ -75,7 +75,7 @@ func SaveUser(dbPool *pgxpool.Pool, user *User) error { return nil } -func AuthenticatedMiddleware(next echo.HandlerFunc) echo.HandlerFunc { +func AuthenticatedPageMiddleware(next echo.HandlerFunc) echo.HandlerFunc { return func(c echo.Context) error { isSignedIn := IsSignedIn(c) @@ -89,3 +89,18 @@ func AuthenticatedMiddleware(next echo.HandlerFunc) echo.HandlerFunc { return next(c) } } + +func AuthenticatedEndpointMiddleware(next echo.HandlerFunc) echo.HandlerFunc { + return func(c echo.Context) error { + isSignedIn := IsSignedIn(c) + + // Check if user is authenticated + if !isSignedIn { + // Return 401 if not authenticated + return c.String(http.StatusUnauthorized, "Unauthorized") + } + + // Proceed with the request if authenticated + return next(c) + } +}