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:
@@ -1,7 +1,8 @@
|
||||
import db from "@/lib/db";
|
||||
import { NextResponse } from "next/server";
|
||||
import { withReadAuth, withUserAuth } from "@/lib/middleware/auth";
|
||||
|
||||
export async function GET(req, { params }) {
|
||||
async function getContractHandler(req, { params }) {
|
||||
const { id } = await params;
|
||||
|
||||
const contract = db
|
||||
@@ -20,7 +21,7 @@ export async function GET(req, { params }) {
|
||||
return NextResponse.json(contract);
|
||||
}
|
||||
|
||||
export async function DELETE(req, { params }) {
|
||||
async function deleteContractHandler(req, { params }) {
|
||||
const { id } = params;
|
||||
|
||||
try {
|
||||
@@ -57,3 +58,7 @@ export async function DELETE(req, { params }) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Protected routes - require authentication
|
||||
export const GET = withReadAuth(getContractHandler);
|
||||
export const DELETE = withUserAuth(deleteContractHandler);
|
||||
|
||||
Reference in New Issue
Block a user