up
This commit is contained in:
@@ -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{
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user