From 899444e815c59995a2cc731813784504ac88fe45 Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Mon, 20 Jul 2026 02:11:15 +0100 Subject: [PATCH] Enhance production sidebar by adding Printer Profiles and Filament Profiles sections, improving navigation for users. Update cookie utility functions to handle authentication expiry and max age more effectively, ensuring better session management. --- src/database/sidebars/production.js | 13 ++++++++++++ src/utils/cookies.js | 31 +++++++++++++++++++---------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/database/sidebars/production.js b/src/database/sidebars/production.js index 7dd6d4f..bf994aa 100644 --- a/src/database/sidebars/production.js +++ b/src/database/sidebars/production.js @@ -24,11 +24,24 @@ const productionSidebarItems = [ label: 'Sub Jobs', path: '/dashboard/production/subjobs' }, + { type: 'divider' }, { key: 'gcodeFiles', iconKey: 'gcodeFile', label: 'GCode Files', path: '/dashboard/production/gcodefiles' + }, + { + key: 'printerProfiles', + iconKey: 'printerProfile', + label: 'Printer Profiles', + path: '/dashboard/production/printerprofiles' + }, + { + key: 'filamentProfiles', + iconKey: 'filamentProfile', + label: 'Filament Profiles', + path: '/dashboard/production/filamentprofiles' } ] diff --git a/src/utils/cookies.js b/src/utils/cookies.js index f396afd..7440375 100644 --- a/src/utils/cookies.js +++ b/src/utils/cookies.js @@ -6,6 +6,18 @@ const COOKIE_OPTIONS = { maxAge: 7 * 24 * 60 * 60 // 7 days in seconds } +const getAuthExpiryTime = (expiresAt) => { + const numericExpiry = Number(expiresAt) + if (Number.isFinite(numericExpiry) && numericExpiry > 0) return numericExpiry + return new Date(expiresAt).getTime() +} + +const getAuthCookieMaxAge = (expiresAt) => { + const expiryTime = getAuthExpiryTime(expiresAt) + if (!Number.isFinite(expiryTime)) return COOKIE_OPTIONS.maxAge + return Math.max(Math.floor((expiryTime - Date.now()) / 1000), 1) +} + /** * Set a cookie with authentication data * @param {string} name - Cookie name @@ -137,10 +149,10 @@ export const validateAuthCookies = () => { return false } - const now = new Date() - const expirationDate = new Date(expiresAt) + const now = Date.now() + const expirationTime = getAuthExpiryTime(expiresAt) - if (expirationDate <= now) { + if (!Number.isFinite(expirationTime) || expirationTime <= now) { // Cookies are expired, clean them up clearAuthCookies() return false @@ -167,9 +179,7 @@ export const checkAuthCookiesExpiry = (minutesBeforeExpiry = 5) => { return { isExpiringSoon: false, timeRemaining: 0 } } - const now = new Date() - const expirationDate = new Date(expiresAt) - const timeRemaining = expirationDate - now + const timeRemaining = getAuthExpiryTime(expiresAt) - Date.now() const minutesRemaining = timeRemaining / (1000 * 60) return { @@ -240,20 +250,21 @@ export const setAuthCookies = (authData) => { } let success = true + const maxAge = getAuthCookieMaxAge(authData.expires_at) if (authData.access_token) { success = success && setCookie('authToken', authData.access_token, { - maxAge: 7 * 24 * 60 * 60 - }) // 7 days + maxAge + }) } if (authData.expires_at) { success = success && setCookie('authExpiresAt', authData.expires_at, { - maxAge: 7 * 24 * 60 * 60 + maxAge }) } @@ -267,7 +278,7 @@ export const setAuthCookies = (authData) => { success = success && setCookie('user', JSON.stringify(userObject), { - maxAge: 7 * 24 * 60 * 60 + maxAge }) }