diff --git a/components/app/windows/settings.vue b/components/app/windows/settings.vue index 9301b93..c87f542 100644 --- a/components/app/windows/settings.vue +++ b/components/app/windows/settings.vue @@ -112,6 +112,7 @@ const submitChangeAction = async (action: string) => { body: JSON.stringify({ action: actionMatch.name, value: actionMatch.sendValue, + jsonValue: "", }), }); diff --git a/server/api/user/sendUserChanges.post.ts b/server/api/user/sendUserChanges.post.ts index 181e13e..f3b96fb 100644 --- a/server/api/user/sendUserChanges.post.ts +++ b/server/api/user/sendUserChanges.post.ts @@ -24,6 +24,30 @@ export default defineEventHandler(async (event) => { if (body.value.match()) { allowed = false; } + // Use Static values for now. + const requestChange = "groq_api_key"; + const apiKeyqq = body.value.match(clearBadDataRegex); + const allowedColumns = ["groq_api_key", "another_column_name"]; + + if (!allowedColumns.includes(requestChange)) { + throw new Error("Invalid column name provided"); + } + const sqlC = await sql.unsafe` + UPDATE user_other_data SET ${requestChange} = ${apiKeyqq[0]} + WHERE username = ${checkUserToken[0].username}`; + + /** + * // Example of how requestChange might be validated + const allowedColumns = ['groq_api_key', 'another_column_name']; + + if (!allowedColumns.includes(requestChange)) { + throw new Error('Invalid column name provided'); + } + + const sqlC = await sql` + UPDATE user_other_data SET ${sql.identifier([requestChange])} = ${apiKeyqq[0]} + WHERE username = ${checkUserToken[0].username}`; + */ return { body: body, allowed: allowed,