2025-09-18 21:12:50 -06:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import Cookies from "js-cookie";
|
|
|
|
|
import { useRouter } from "next/navigation";
|
2026-02-09 17:17:52 -06:00
|
|
|
import { useEffect, useState } from "react";
|
2025-09-18 21:12:50 -06:00
|
|
|
|
|
|
|
|
import "./Logout.css";
|
|
|
|
|
|
|
|
|
|
export default function Logout() {
|
|
|
|
|
const router = useRouter();
|
2026-02-09 17:17:52 -06:00
|
|
|
const [userName, setUserName] = useState<string | null>(null);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setUserName(Cookies.get("user") ?? null);
|
|
|
|
|
}, []);
|
2025-09-18 21:12:50 -06:00
|
|
|
|
|
|
|
|
const handleLogout = () => {
|
|
|
|
|
Cookies.remove("token", { path: "/" });
|
2025-12-08 18:02:33 -06:00
|
|
|
Cookies.remove("role", { path: "/" });
|
|
|
|
|
Cookies.remove("user", { path: "/" });
|
|
|
|
|
|
2025-09-18 21:12:50 -06:00
|
|
|
router.push("/");
|
2026-01-22 10:11:08 -06:00
|
|
|
router.refresh();
|
2025-09-18 21:12:50 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2026-02-09 17:17:52 -06:00
|
|
|
<section className="session">
|
|
|
|
|
{userName && <h2 className="userName">{userName}</h2>}
|
2025-09-22 14:53:19 -06:00
|
|
|
<button onClick={handleLogout} className="button button-logout">
|
|
|
|
|
Cerrar sesión
|
|
|
|
|
</button>
|
2026-02-09 17:17:52 -06:00
|
|
|
</section>
|
2025-09-18 21:12:50 -06:00
|
|
|
);
|
|
|
|
|
}
|