Refactor login flow with reset token support
All checks were successful
Automated Container Build / build-and-push (push) Successful in 1m6s

This commit is contained in:
Elijah 2026-07-12 07:53:48 -07:00
parent f0548bcc6e
commit 95af276d2e
11 changed files with 679 additions and 226 deletions

View file

@ -1,49 +0,0 @@
import { NextRequest, NextResponse } from "next/server";
import { getIronSession } from "iron-session";
import type { SessionData } from "@/lib/auth";
const sessionOptions = {
password:
process.env.SESSION_SECRET ||
"dev-session-secret-change-in-production-must-be-32-chars",
cookieName: "study-app-session",
};
// Routes that don't require authentication
const publicPaths = ["/login", "/api/auth", "/shared"];
export async function middleware(request: NextRequest) {
const { pathname } = request.nextUrl;
// Allow public routes
if (publicPaths.some((path) => pathname.startsWith(path))) {
return NextResponse.next();
}
// Allow static assets and Next.js internals
if (
pathname.startsWith("/_next") ||
pathname.startsWith("/favicon") ||
pathname.includes(".")
) {
return NextResponse.next();
}
// Check session
const response = NextResponse.next();
const session = await getIronSession<SessionData>(
request,
response,
sessionOptions
);
if (!session.isAuthenticated) {
return NextResponse.redirect(new URL("/login", request.url));
}
return response;
}
export const config = {
matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
};