refactor, sketch SSE implementation

This commit is contained in:
Carl Pearson
2024-10-19 06:02:54 -06:00
parent 459e899efe
commit 22a82d0e4c
11 changed files with 266 additions and 124 deletions

25
handlers/middleware.go Normal file
View File

@@ -0,0 +1,25 @@
package handlers
import (
"fmt"
"net/http"
"github.com/labstack/echo/v4"
)
func AuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
session, err := store.Get(c.Request(), "session")
if err != nil {
return c.String(http.StatusInternalServerError, "Error: Unable to retrieve session")
}
userID, ok := session.Values["user_id"]
if !ok {
fmt.Println("authMiddleware: session does not contain user_id. Redirect to /login")
// return c.String(http.StatusForbidden, "not logged in")
return c.Redirect(http.StatusSeeOther, "/login")
}
c.Set("user_id", userID)
return next(c)
}
}