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.
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good

This commit is contained in:
Tom Butcher 2026-07-20 02:11:15 +01:00
parent ce611e52f3
commit 899444e815
2 changed files with 34 additions and 10 deletions

View File

@ -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'
}
]

View File

@ -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
})
}