Files
helios-evcs/apps/web/middleware.ts
Timothy Yin 2cb89c74b3 feat(dashboard): add transactions and users management pages with CRUD functionality
feat(auth): implement login page and authentication middleware
feat(sidebar): create sidebar component with user info and navigation links
feat(api): establish API client for interacting with backend services
2026-03-10 15:17:32 +08:00

28 lines
756 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { NextRequest, NextResponse } from "next/server";
export async function middleware(request: NextRequest) {
const { pathname } = request.nextUrl;
// 只保护 /dashboard 路由
if (!pathname.startsWith("/dashboard")) {
return NextResponse.next();
}
// 检查 better-auth session cookiecookie 前缀是 helios_auth
const sessionCookie =
request.cookies.get("helios_auth.session_token") ??
request.cookies.get("__Secure-helios_auth.session_token");
if (!sessionCookie) {
const loginUrl = new URL("/login", request.url);
loginUrl.searchParams.set("from", pathname);
return NextResponse.redirect(loginUrl);
}
return NextResponse.next();
}
export const config = {
matcher: ["/dashboard/:path*"],
};