chore: Secure routes with auth middleware, update text and fix minor bugs
This commit is contained in:
27
src/proxy.ts
Normal file
27
src/proxy.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import type { NextRequest } from 'next/server';
|
||||
|
||||
export function proxy(request: NextRequest) {
|
||||
const token = request.cookies.get('auth_token')?.value;
|
||||
const path = request.nextUrl.pathname;
|
||||
|
||||
// Protect /admin routes
|
||||
if (path.startsWith('/admin')) {
|
||||
if (token !== 'admin') {
|
||||
return NextResponse.redirect(new URL('/login', request.url));
|
||||
}
|
||||
}
|
||||
|
||||
// Protect /dashboard routes
|
||||
if (path.startsWith('/dashboard')) {
|
||||
if (!token) {
|
||||
return NextResponse.redirect(new URL('/login', request.url));
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: ['/dashboard/:path*', '/admin/:path*']
|
||||
};
|
||||
Reference in New Issue
Block a user