feat: add authentication test page and API testing scripts; implement debug auth endpoint and enhance task route with read permissions
This commit is contained in:
37
src/app/api/debug-auth/route.js
Normal file
37
src/app/api/debug-auth/route.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import { auth } from "@/lib/auth"
|
||||
import { NextResponse } from "next/server"
|
||||
|
||||
export const GET = auth(async (req) => {
|
||||
try {
|
||||
console.log("=== DEBUG AUTH ENDPOINT ===")
|
||||
console.log("Request URL:", req.url)
|
||||
console.log("Auth object:", req.auth)
|
||||
|
||||
if (!req.auth?.user) {
|
||||
return NextResponse.json({
|
||||
error: "No session found",
|
||||
debug: {
|
||||
hasAuth: !!req.auth,
|
||||
authKeys: req.auth ? Object.keys(req.auth) : [],
|
||||
}
|
||||
}, { status: 401 })
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
message: "Authenticated",
|
||||
user: req.auth.user,
|
||||
debug: {
|
||||
authKeys: Object.keys(req.auth),
|
||||
userKeys: Object.keys(req.auth.user)
|
||||
}
|
||||
})
|
||||
|
||||
} catch (error) {
|
||||
console.error("Auth debug error:", error)
|
||||
return NextResponse.json({
|
||||
error: "Auth error",
|
||||
message: error.message,
|
||||
stack: error.stack
|
||||
}, { status: 500 })
|
||||
}
|
||||
})
|
||||
@@ -1,6 +1,7 @@
|
||||
import db from "@/lib/db";
|
||||
import { NextResponse } from "next/server";
|
||||
import { withUserAuth } from "@/lib/middleware/auth";
|
||||
import { withUserAuth, withReadAuth } from "@/lib/middleware/auth";
|
||||
import { getAllTaskTemplates } from "@/lib/queries/tasks";
|
||||
|
||||
// POST: create new template
|
||||
async function createTaskHandler(req) {
|
||||
@@ -20,5 +21,12 @@ async function createTaskHandler(req) {
|
||||
return NextResponse.json({ success: true });
|
||||
}
|
||||
|
||||
// GET: Get all task templates
|
||||
async function getTasksHandler(req) {
|
||||
const templates = getAllTaskTemplates();
|
||||
return NextResponse.json(templates);
|
||||
}
|
||||
|
||||
// Protected routes - require authentication
|
||||
export const GET = withReadAuth(getTasksHandler);
|
||||
export const POST = withUserAuth(createTaskHandler);
|
||||
|
||||
Reference in New Issue
Block a user