Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion client/src/components/Canvas.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,34 @@ export const Canvas = () => {
const [hoveredHandle, setHoveredHandle] = useState(null); // { id, dir }

const handleLogout = async () => {
// placeholder
try {
const token = localStorage.getItem("token");
if (!token) {
toast.error("You are not logged in.");
return;
}

const res = await fetch("http://localhost:3000/api/auth/logout", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ token }),
});

if (!res.ok) {
const data = await res.json().catch(() => ({}));
toast.error(data.message || "Logout failed");
return;
}

// Clear auth state and redirect
localStorage.removeItem("token");
setIsLoggedIn(false);
toast.success("Logged out successfully");
window.location.href = "/";
} catch (err) {
console.error("Logout error:", err);
toast.error("Logout failed. Please try again.");
}
};

// --- Helpers ---
Expand Down
Loading