Add debug logging and update API authentication
- Add comprehensive logging to all interest API endpoints and NocoDB utilities - Update create-interest and delete-interest endpoints to accept additional x-tag value - Add missing imports for deleteInterest and updateInterest functions - Log request details, processing steps, and errors for better debugging
This commit is contained in:
@@ -2,21 +2,31 @@ import { createInterest } from "../utils/nocodb";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const xTagHeader = getRequestHeader(event, "x-tag");
|
||||
console.log('[create-interest] Request received with x-tag:', xTagHeader);
|
||||
|
||||
if (!xTagHeader || xTagHeader !== "094ut234") {
|
||||
if (!xTagHeader || (xTagHeader !== "094ut234" && xTagHeader !== "pjnvü1230")) {
|
||||
console.error('[create-interest] Authentication failed - invalid x-tag:', xTagHeader);
|
||||
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
||||
}
|
||||
|
||||
try {
|
||||
const body = await readBody(event);
|
||||
console.log('[create-interest] Request body fields:', body ? Object.keys(body) : 'none');
|
||||
|
||||
if (!body || Object.keys(body).length === 0) {
|
||||
console.error('[create-interest] No data provided');
|
||||
throw createError({ statusCode: 400, statusMessage: "No data provided" });
|
||||
}
|
||||
|
||||
console.log('[create-interest] Creating new interest with fields:', Object.keys(body));
|
||||
const createdInterest = await createInterest(body);
|
||||
console.log('[create-interest] Successfully created interest with ID:', createdInterest.Id);
|
||||
|
||||
return createdInterest;
|
||||
} catch (error) {
|
||||
console.error('[create-interest] Error occurred:', error);
|
||||
console.error('[create-interest] Error stack:', error instanceof Error ? error.stack : 'No stack trace');
|
||||
|
||||
if (error instanceof Error) {
|
||||
throw createError({ statusCode: 500, statusMessage: error.message });
|
||||
} else {
|
||||
|
||||
@@ -1,21 +1,33 @@
|
||||
import { deleteInterest } from '~/server/utils/nocodb';
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const xTagHeader = getRequestHeader(event, "x-tag");
|
||||
console.log('[delete-interest] Request received with x-tag:', xTagHeader);
|
||||
|
||||
if (!xTagHeader || xTagHeader !== "094ut234") {
|
||||
if (!xTagHeader || (xTagHeader !== "094ut234" && xTagHeader !== "pjnvü1230")) {
|
||||
console.error('[delete-interest] Authentication failed - invalid x-tag:', xTagHeader);
|
||||
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
||||
}
|
||||
|
||||
try {
|
||||
const body = await readBody(event);
|
||||
const { id } = body;
|
||||
console.log('[delete-interest] Request body:', { id });
|
||||
|
||||
if (!id) {
|
||||
console.error('[delete-interest] Missing ID in request');
|
||||
throw createError({ statusCode: 400, statusMessage: "ID is required" });
|
||||
}
|
||||
|
||||
console.log('[delete-interest] Deleting interest:', id);
|
||||
const result = await deleteInterest(id);
|
||||
console.log('[delete-interest] Successfully deleted interest:', id);
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error('[delete-interest] Error occurred:', error);
|
||||
console.error('[delete-interest] Error stack:', error instanceof Error ? error.stack : 'No stack trace');
|
||||
|
||||
if (error instanceof Error) {
|
||||
throw createError({ statusCode: 500, statusMessage: error.message });
|
||||
} else {
|
||||
|
||||
@@ -1,19 +1,26 @@
|
||||
import { updateInterest } from '~/server/utils/nocodb';
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const xTagHeader = getRequestHeader(event, "x-tag");
|
||||
console.log('[update-interest] Request received with x-tag:', xTagHeader);
|
||||
|
||||
if (!xTagHeader || (xTagHeader !== "094ut234" && xTagHeader !== "pjnvü1230")) {
|
||||
console.error('[update-interest] Authentication failed - invalid x-tag:', xTagHeader);
|
||||
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
||||
}
|
||||
|
||||
try {
|
||||
const body = await readBody(event);
|
||||
const { id, data } = body;
|
||||
console.log('[update-interest] Request body:', { id, dataKeys: data ? Object.keys(data) : 'none' });
|
||||
|
||||
if (!id) {
|
||||
console.error('[update-interest] Missing ID in request');
|
||||
throw createError({ statusCode: 400, statusMessage: "ID is required" });
|
||||
}
|
||||
|
||||
if (!data || Object.keys(data).length === 0) {
|
||||
console.error('[update-interest] No data provided for update');
|
||||
throw createError({ statusCode: 400, statusMessage: "No data provided for update" });
|
||||
}
|
||||
|
||||
@@ -21,11 +28,18 @@ export default defineEventHandler(async (event) => {
|
||||
const updateData = { ...data };
|
||||
if ('Id' in updateData) {
|
||||
delete updateData.Id;
|
||||
console.log('[update-interest] Removed Id from update data');
|
||||
}
|
||||
|
||||
console.log('[update-interest] Updating interest:', id, 'with fields:', Object.keys(updateData));
|
||||
const updatedInterest = await updateInterest(id, updateData);
|
||||
console.log('[update-interest] Successfully updated interest:', id);
|
||||
|
||||
return updatedInterest;
|
||||
} catch (error) {
|
||||
console.error('[update-interest] Error occurred:', error);
|
||||
console.error('[update-interest] Error stack:', error instanceof Error ? error.stack : 'No stack trace');
|
||||
|
||||
if (error instanceof Error) {
|
||||
throw createError({ statusCode: 500, statusMessage: error.message });
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user