Some checks failed
Build Frontend / build (push) Failing after 7s
Replaces imports from 'components/ui' with 'components/common' across the app and dashboard pages, and updates model and API imports to use new paths under 'lib'. Removes redundant authentication checks from several dashboard pages. Adds new dashboard components and utility files, and reorganizes hooks and services into the 'lib' directory for improved structure.
26 lines
757 B
TypeScript
26 lines
757 B
TypeScript
import { NextResponse } from 'next/server';
|
|
import type { NextRequest } from 'next/server';
|
|
|
|
export function middleware(request: NextRequest) {
|
|
const { pathname } = request.nextUrl;
|
|
|
|
// Protect dashboard routes
|
|
if (pathname.startsWith('/dashboard')) {
|
|
const authToken = request.cookies.get('Authorization')?.value;
|
|
|
|
if (!authToken) {
|
|
// Redirect to login if no token is found
|
|
const loginUrl = new URL('/auth/login', request.url);
|
|
loginUrl.searchParams.set('redirectUrl', pathname);
|
|
return NextResponse.redirect(loginUrl);
|
|
}
|
|
}
|
|
|
|
return NextResponse.next();
|
|
}
|
|
|
|
// See "Matching Paths" below to learn more
|
|
export const config = {
|
|
matcher: ['/dashboard/:path*'],
|
|
};
|