Update portal.go

This commit is contained in:
Lizandro Guarnizo
2026-05-15 16:19:17 -05:00
parent 6ba096e97e
commit 41fe416986
+10 -1
View File
@@ -2,6 +2,7 @@ package auth
import (
"errors"
"log"
"github.com/gofiber/fiber/v2"
"github.com/sujit-baniya/fiber-boilerplate/app"
@@ -14,11 +15,13 @@ const portalSessionKey = "portal_user_id"
func PortalUser(c *fiber.Ctx) (*models.PortalUser, error) {
store := app.Http.Session.Get(c)
raw := store.Get(portalSessionKey)
log.Printf("[PORTAL SESSION] GET %s → cookie=%q raw=%v", c.Path(), c.Cookies("session_id"), raw)
if raw == nil {
return nil, errors.New("no portal session")
}
id, ok := raw.(uint)
if !ok {
log.Printf("[PORTAL SESSION] type assertion failed: %T", raw)
return nil, errors.New("invalid portal session")
}
u, err := models.GetPortalUserByID(id)
@@ -37,10 +40,16 @@ func SetPortalSession(c *fiber.Ctx, userID uint) error {
store := app.Http.Session.Get(c)
// Regenerar ID de sesión para evitar session fixation
if err := store.Regenerate(); err != nil {
log.Printf("[PORTAL SESSION] Regenerate error: %v", err)
return err
}
store.Set(portalSessionKey, userID)
return store.Save()
if err := store.Save(); err != nil {
log.Printf("[PORTAL SESSION] Save error: %v", err)
return err
}
log.Printf("[PORTAL SESSION] SET userID=%d cookie=%q", userID, c.Cookies("session_id"))
return nil
}
// DestroyPortalSession elimina la sesión del portal.