Skip to content

Commit c772abc

Browse files
Copilotstnguyen90
andcommitted
Fix: Handle empty string initialization for API key expire parameter
- Updated initialization logic to handle both null and invalid date values (including empty strings) - Removed the check for expirationSelect !== null to allow proper initialization when "Never" is selected - Added isValidDate check before ISO date conversion to prevent converting invalid dates to 'n/a' - This fixes the issue where API keys couldn't be created with "Never" expiration when the parent component initializes expire as an empty string Co-authored-by: stnguyen90 <[email protected]>
1 parent 74452a4 commit c772abc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/lib/components/expirationInput.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@
123123
let hasUserInteracted = false;
124124
125125
$: {
126-
// Set initial value if value is null on first load
127-
if (!initialized && value === null && expirationSelect !== null) {
126+
// Set initial value if value is null or invalid on first load
127+
if (!initialized && (value === null || !isValidDate(value))) {
128128
value = expirationSelect === 'custom' ? expirationCustom : expirationSelect;
129129
initialized = true;
130130
}
@@ -134,8 +134,8 @@
134134
value = expirationSelect === 'custom' ? expirationCustom : expirationSelect;
135135
}
136136
137-
// Only convert to ISO date if value is not null
138-
if (value !== null) {
137+
// Only convert to ISO date if value is not null and is a valid date
138+
if (value !== null && isValidDate(value)) {
139139
value = toLocaleDateISO(new Date(value).getTime());
140140
}
141141
}

0 commit comments

Comments
 (0)