diff --git a/app/components/token/ResponseSettingsCard.vue b/app/components/token/ResponseSettingsCard.vue
index 72ac47f..87d3a48 100644
--- a/app/components/token/ResponseSettingsCard.vue
+++ b/app/components/token/ResponseSettingsCard.vue
@@ -30,7 +30,7 @@
-
@@ -81,9 +81,13 @@ const responseEnabled = ref(false)
const responseStatus = ref('200')
const responseHeadersText = ref('')
const responseBody = ref('')
+const isFormInitialized = ref(false)
const statusSummary = computed(() => {
- const statusLabel = responseStatus.value?.trim().length ? responseStatus.value : '200'
+ let statusLabel = '200';
+ if (!responseStatus.value) {
+ statusLabel = responseStatus.value?.trim().length ? responseStatus.value : '200'
+ }
return responseEnabled.value ? `Custom response enabled ยท ${statusLabel}` : 'Custom responses disabled'
})
@@ -119,14 +123,17 @@ const textToHeaders = (input: string): Record | null => {
return Object.keys(out).length ? out : null
}
-// Watch for token data changes and update form
+// Watch for token data changes and update form only on initial load
watch(tokenData, (data) => {
- if (!data) return
+ if (!data || isFormInitialized.value) {
+ return
+ }
responseEnabled.value = Boolean(data.responseEnabled)
responseStatus.value = String(data.responseStatus ?? 200)
responseHeadersText.value = headersToText(data.responseHeaders as Record | null)
responseBody.value = data.responseBody ?? ''
+ isFormInitialized.value = true
}, { immediate: true })
const handleToggleEnabled = async (enabled: boolean | 'indeterminate') => {
diff --git a/server/api/token/[token]/index.ts b/server/api/token/[token]/index.ts
index 8a001c2..c66f23a 100644
--- a/server/api/token/[token]/index.ts
+++ b/server/api/token/[token]/index.ts
@@ -34,13 +34,13 @@ export default defineEventHandler(async (event: H3Event) =>
const payload = body as Record
const enabled = Boolean(payload.responseEnabled)
const status = Number(payload.responseStatus ?? 200)
- const headers = (payload.responseHeaders as unknown) as Record | null
+ const headers = (payload.responseHeaders as unknown) as string | null
const responseBody = (payload.responseBody as unknown) as string | null
await db.tokens.update(sessionId, tokenId, {
responseEnabled: enabled,
responseStatus: status,
- responseHeaders: headers ? JSON.stringify(headers) : null,
+ responseHeaders: headers,
responseBody,
})