feat: add password change functionality and dependencies

This commit is contained in:
decolua
2026-01-09 17:29:11 +07:00
parent bf6e09bb6f
commit 23cfb19459
8 changed files with 320 additions and 3 deletions
+37
View File
@@ -0,0 +1,37 @@
import { NextResponse } from "next/server";
import { jwtVerify } from "jose";
const SECRET = new TextEncoder().encode(
process.env.JWT_SECRET || "9router-default-secret-change-me"
);
export async function middleware(request) {
const { pathname } = request.nextUrl;
// Protect all dashboard routes
if (pathname.startsWith("/dashboard")) {
const token = request.cookies.get("auth_token")?.value;
if (!token) {
return NextResponse.redirect(new URL("/login", request.url));
}
try {
await jwtVerify(token, SECRET);
return NextResponse.next();
} catch (err) {
return NextResponse.redirect(new URL("/login", request.url));
}
}
// Redirect / to /dashboard if logged in, or /dashboard if it's the root
if (pathname === "/") {
return NextResponse.redirect(new URL("/dashboard", request.url));
}
return NextResponse.next();
}
export const config = {
matcher: ["/", "/dashboard/:path*"],
};