feat(audit-logging): Replace req.session with req.auth for audit logging in notes and projects

This commit is contained in:
Chop
2025-07-10 00:08:59 +02:00
parent b1a78bf7a8
commit 38b0682d83
8 changed files with 423 additions and 8 deletions

37
test-auth-session.mjs Normal file
View File

@@ -0,0 +1,37 @@
import { auth } from "@/lib/auth";
// Test what the auth session looks like
console.log("Testing authentication session structure...\n");
async function testAuth() {
try {
// Create a mock request
const mockReq = {
url: "http://localhost:3000/api/projects",
method: "GET",
headers: new Map([
["cookie", ""], // Add any cookies if needed
]),
};
// This is how the auth middleware would wrap a handler
const testHandler = auth(async (req) => {
console.log("=== Authentication Session Debug ===");
console.log("req.auth:", JSON.stringify(req.auth, null, 2));
console.log("req.auth?.user:", JSON.stringify(req.auth?.user, null, 2));
console.log("req.auth?.user?.id:", req.auth?.user?.id);
console.log("req.user:", JSON.stringify(req.user, null, 2));
console.log("req.user?.id:", req.user?.id);
return { success: true };
});
// This would normally be called by Next.js
const result = await testHandler(mockReq);
console.log("Handler result:", result);
} catch (error) {
console.error("Auth test failed:", error);
}
}
testAuth();