My-Weekly-ToDo-List/src/middleware.ts
mARTin d92a8c7210 feat: add task actions (notes/delete) and refine animation logic
- Added 'onDelete' and 'onNotes' support to TaskItem.
- Implemented hover actions (Delete and Notes icons) for tasks.
- Added Notes Modal for editing task markdown content.
- Simplified navigation animation to remove blank flash (single-phase slide-in).
- Fixed syntax error in updateTask function.
- Updated styles for modal and task actions.
2026-02-01 12:25:53 +01:00

43 lines
1.2 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import { getToken } from 'next-auth/jwt';
export async function middleware(request: NextRequest) {
// Skip middleware for public paths
if (
request.nextUrl.pathname.startsWith('/auth') ||
request.nextUrl.pathname.startsWith('/api/auth') || // CRITICAL: Allow NextAuth API routes
request.nextUrl.pathname.startsWith('/_next') ||
request.nextUrl.pathname === '/favicon.ico'
) {
return NextResponse.next();
}
// Check if user is authenticated using NextAuth
const token = await getToken({
req: request,
secret: process.env.NEXTAUTH_SECRET,
});
// Redirect to login if not authenticated
if (!token && !request.nextUrl.pathname.startsWith('/auth')) {
const url = request.nextUrl.clone();
url.pathname = '/auth/login';
url.searchParams.set('callbackUrl', request.nextUrl.pathname);
return NextResponse.redirect(url);
}
return NextResponse.next();
}
export const config = {
matcher: [
/*
* Match all request paths except:
* - api/auth/* (NextAuth endpoints)
* - _next/static (static files)
* - _next/image (image optimization)
* - favicon.ico
*/
'/((?!_next/static|_next/image|favicon.ico).*)',
],
};