feat: upgrade next-auth to v5.0.0-beta.29 and refactor authentication middleware
- Updated next-auth dependency in package.json to version 5.0.0-beta.29. - Refactored create-admin script to use a valid email format. - Implemented authentication middleware for various API routes to enforce access control. - Refactored API route handlers to improve readability and maintainability. - Enhanced error handling in authentication error page. - Added detailed tests for authentication flow, including protected routes and NextAuth endpoints.
This commit is contained in:
@@ -5,9 +5,10 @@ import {
|
||||
} from "@/lib/queries/tasks";
|
||||
import { NextResponse } from "next/server";
|
||||
import db from "@/lib/db";
|
||||
import { withReadAuth, withUserAuth } from "@/lib/middleware/auth";
|
||||
|
||||
// GET: Get all project tasks or task templates based on query params
|
||||
export async function GET(req) {
|
||||
async function getProjectTasksHandler(req) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const projectId = searchParams.get("project_id");
|
||||
|
||||
@@ -23,7 +24,7 @@ export async function GET(req) {
|
||||
}
|
||||
|
||||
// POST: Create a new project task
|
||||
export async function POST(req) {
|
||||
async function createProjectTaskHandler(req) {
|
||||
try {
|
||||
const data = await req.json();
|
||||
|
||||
@@ -113,3 +114,7 @@ export async function PATCH(req) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Protected routes - require authentication
|
||||
export const GET = withReadAuth(getProjectTasksHandler);
|
||||
export const POST = withUserAuth(createProjectTaskHandler);
|
||||
|
||||
Reference in New Issue
Block a user