diff --git a/server/.env.sample b/server/.env.sample index 13ff683..64c7f6c 100644 --- a/server/.env.sample +++ b/server/.env.sample @@ -5,4 +5,5 @@ PORT=8000 ACCESS_TOKEN_SECRET= # your access token secret here for encryption. ACCESS_TOKEN_EXPIRY= # ex: 1d REFRESH_TOKEN_SECRET= # your refresh token secret here for encryption. -REFRESH_TOKEN_EXPIRY= # ex: 10d \ No newline at end of file +REFRESH_TOKEN_EXPIRY= # ex: 10d +VITE_BACKEND_URL=* # backend url for frontend reference ex: http://localhost:8000 \ No newline at end of file diff --git a/src/components/Dashboard.jsx b/src/components/Dashboard.jsx index 378f86d..fd3d796 100644 --- a/src/components/Dashboard.jsx +++ b/src/components/Dashboard.jsx @@ -1,5 +1,5 @@ -import { Plus, TrendingUp, TrendingDown, Wallet, IndianRupee, Calendar, Tag, Filter, Search, Eye, EyeOff, ChevronDown, ChevronUp, ChevronLeft, ChevronRight, Trash2, Download, Moon, Sun, Target } from "lucide-react"; +import { Plus, TrendingUp, TrendingDown, Wallet, IndianRupee, Calendar, Tag, Filter, Search, Eye, EyeOff, ChevronDown, ChevronUp, ChevronLeft, ChevronRight, Trash2, Download, Moon, Sun, Target, LogOut } from "lucide-react"; import { useTransactions } from "./TransactionContext"; import { useCurrency } from "./CurrencyContext"; @@ -240,6 +240,24 @@ export default function Dashboard() { downloadCSV(s) } +const BACKEND_URL = import.meta.env.VITE_BACKEND_URL; +const handleLogout = () => { + // Remove tokens + localStorage.removeItem("accessToken"); + localStorage.removeItem("refreshToken"); + + // Call backend logout + fetch(`${BACKEND_URL}/api/v1/users/logout`, { + method: "POST", + credentials: "include" + }).catch(err => console.log("Logout API failed:", err)); + + // Redirect to login + window.location.href = "/login"; +}; + + + return (