Update sendUserChanges to make the settings system work.

This commit is contained in:
yuanhau 2025-06-14 21:04:06 +08:00
parent ad0f13a1a2
commit 85c3332c76
3 changed files with 23 additions and 16 deletions

View file

@ -81,6 +81,9 @@ export default defineEventHandler(async (event) => {
VALUES (${fetchUserInfoAgain[0].username}, ${newToken})
`;
const getUserFirstName = await sql`
select * from user_other_data`;
setCookie(event, "token", newToken);
return {
user: fetchUserInfoAgain,

View file

@ -12,23 +12,26 @@ export default defineEventHandler(async (event) => {
const body = await readBody(event);
if (body.jsonValue.length === 0) {
const clearBadDataRegex = /[@-_.+a-zA-Z0-9]{2,}/;
let allowed = true;
if (body.value.match()) {
allowed = false;
}
// Use Static values for now.
const requestChange = "groq_api_key";
const requestChange = body.name;
const apiKeyqq = body.value.match(clearBadDataRegex);
const allowedColumns = ["groq_api_key", "another_column_name"];
const allowedColumns = ["firstname", "email"];
if (!allowedColumns.includes(requestChange)) {
throw new Error("Invalid column name provided");
return {
error: "ERR_NOT_ALLOWED",
};
} else if (requestChange === "name") {
const sqlC = await sql`
UPDATE users SET firstname = ${apiKeyqq[0]}
WHERE username = ${token.user}`;
return {
sqlC: sqlC,
success: true,
};
}
const sqlC = await sql.unsafe(
`
UPDATE user_other_data SET ${requestChange} = $1
WHERE username = $2`,
`UPDATE user_other_data SET ${requestChange} = $1 WHERE username = $2`,
[apiKeyqq[0], token.user],
);
return {