This commit is contained in:
Lizandro Guarnizo
2026-05-15 15:47:49 -05:00
parent 04fd456a4c
commit f7e8d273d2
2 changed files with 6 additions and 2 deletions
+3 -1
View File
@@ -15,7 +15,9 @@ import (
// ─── Auth ───────────────────────────────────────────────────────────────────── // ─── Auth ─────────────────────────────────────────────────────────────────────
func PortalLoginPage(c *fiber.Ctx) error { func PortalLoginPage(c *fiber.Ctx) error {
if auth.IsPortalLoggedIn(c) { // Usar PortalUser (validación completa) en vez de IsPortalLoggedIn (solo key)
// para evitar loops cuando hay sesión obsoleta pero el usuario ya no existe en DB.
if user, err := auth.PortalUser(c); err == nil && user != nil {
return c.Redirect("/portal/dashboard") return c.Redirect("/portal/dashboard")
} }
return c.Render("portal/login", fiber.Map{ return c.Render("portal/login", fiber.Map{
+3 -1
View File
@@ -7,11 +7,13 @@ import (
) )
// PortalAuth protege las rutas del portal de clientes. // PortalAuth protege las rutas del portal de clientes.
// Si no hay sesión activa, redirige a /portal/login. // Si no hay sesión válida, destruye la sesión obsoleta y redirige a /portal/login.
func PortalAuth() fiber.Handler { func PortalAuth() fiber.Handler {
return func(c *fiber.Ctx) error { return func(c *fiber.Ctx) error {
user, err := auth.PortalUser(c) user, err := auth.PortalUser(c)
if err != nil || user == nil { if err != nil || user == nil {
// Limpiar sesión inválida/obsoleta para romper posibles redirect loops
_ = auth.DestroyPortalSession(c)
return c.Redirect("/portal/login") return c.Redirect("/portal/login")
} }
c.Locals("portalUser", user) c.Locals("portalUser", user)