diff --git a/client/src/pages/api-tokens.tsx b/client/src/pages/api-tokens.tsx index 15d3fc8..f52ee56 100644 --- a/client/src/pages/api-tokens.tsx +++ b/client/src/pages/api-tokens.tsx @@ -80,6 +80,15 @@ const tokenFormSchema = z.object({ expiresIn: z.string().optional(), customDate: z.date().optional(), customTime: z.string().optional(), +}).refine((data) => { + // If custom expiration is selected, a date must be provided + if (data.expiresIn === 'custom' && !data.customDate) { + return false; + } + return true; +}, { + message: "Please select a date for the custom expiration", + path: ["customDate"] }); export default function ApiTokensPage() { @@ -136,7 +145,13 @@ export default function ApiTokensPage() { // If time was selected, add it to the date if (data.customTime) { const [hours, minutes] = data.customTime.split(':').map(Number); - customDate.setHours(hours, minutes, 0, 0); + // Check if hours and minutes are valid numbers + if (!isNaN(hours) && !isNaN(minutes)) { + customDate.setHours(hours, minutes, 0, 0); + } else { + // Default to end of day if time format is invalid + customDate.setHours(23, 59, 59, 999); + } } else { // Default to end of day if no time selected customDate.setHours(23, 59, 59, 999); @@ -516,44 +531,25 @@ export default function ApiTokensPage() { render={({ field }) => ( Custom Time - + +
+ +
+ + + {field.value ? field.value : "23:59"} + +
+
+
- The time when the token will expire + The exact time (HH:MM) when the token will expire