feat (login page): add a sign in / log in page

This commit is contained in:
Pierre Ryssen
2026-03-03 14:47:07 +01:00
parent 7905adb55d
commit 53c5d952b5
19 changed files with 1756 additions and 50 deletions

28
middleware.ts Normal file
View File

@@ -0,0 +1,28 @@
import { NextRequest, NextResponse } from "next/server";
import { getToken } from "next-auth/jwt";
const protectedPaths = ["/dashboard", "/finances", "/instagram", "/tiktok", "/twitch", "/youtube"];
export async function middleware(req: NextRequest) {
const { pathname } = req.nextUrl;
const isProtected = protectedPaths.some((p) => pathname.startsWith(p));
const token = await getToken({ req, secret: process.env.AUTH_SECRET });
if (isProtected && !token) {
const loginUrl = new URL("/", req.url);
return NextResponse.redirect(loginUrl);
}
// Redirect already-authenticated users away from login page
if (pathname === "/" && token) {
const dashboardUrl = new URL("/dashboard", req.url);
return NextResponse.redirect(dashboardUrl);
}
return NextResponse.next();
}
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
};