diff --git a/taskncoffee-app/src/lib/utils.js b/taskncoffee-app/src/lib/utils.js index b20bf01..c8fd144 100644 --- a/taskncoffee-app/src/lib/utils.js +++ b/taskncoffee-app/src/lib/utils.js @@ -1,6 +1,18 @@ import { clsx } from "clsx"; import { twMerge } from "tailwind-merge" +import { jwtDecode as decode } from "jwt-decode"; export function cn(...inputs) { return twMerge(clsx(inputs)); } + +export function jwtexp(token) { + const decoded = decode(token); + if (decoded.exp < Date.now() / 1000) { + console.log("Token expired"); + return false; + } else { + console.log("Token is valid"); + return true; + } +} \ No newline at end of file diff --git a/taskncoffee-app/src/pages/Dashboard.jsx b/taskncoffee-app/src/pages/Dashboard.jsx index 436bb0f..0e10925 100644 --- a/taskncoffee-app/src/pages/Dashboard.jsx +++ b/taskncoffee-app/src/pages/Dashboard.jsx @@ -4,7 +4,7 @@ import './dashboard.css'; import { MenuDock } from '@/components/ui/shadcn-io/menu-dock'; import { Home, Settings, Bell } from 'lucide-react'; import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar'; - +import { jwtexp } from '@/lib/utils'; const menuItems = [ { label: 'home', icon: Home, onClick: () => console.log('Home clicked') }, { label: 'notify', icon: Bell, onClick: () => console.log('Notifications clicked') }, @@ -21,7 +21,9 @@ export default function Dashboard() { { title: "title16", due_date: "2025-10-15", priority: "medium", id: 6, status: "completed" }, { title: "super late title", due_date: "2025-10-15", priority: "low", id: 2, status: "open" } ]; - + const token = localStorage.getItem('access_token'); + const tokenExp = jwtexp(token); + console.log(tokenExp); // Get current date and week const today = new Date(); const currentDay = today.getDay();