Add Better Auth admin authentication
This commit is contained in:
19
proxy.ts
19
proxy.ts
@@ -1,21 +1,18 @@
|
||||
import { NextResponse, type NextRequest } from "next/server";
|
||||
|
||||
import { MOCK_SESSION_COOKIE_NAME } from "@/lib/mock-auth";
|
||||
import { shouldRedirectDashboardRequest } from "@/lib/proxy-auth";
|
||||
import { isAuthenticated } from "@/lib/auth-server";
|
||||
import { shouldRedirectDashboardRequest } from "@/lib/route-guards";
|
||||
|
||||
export function proxy(request: NextRequest) {
|
||||
if (
|
||||
shouldRedirectDashboardRequest(
|
||||
request.nextUrl.pathname,
|
||||
request.cookies.get(MOCK_SESSION_COOKIE_NAME)?.value,
|
||||
)
|
||||
) {
|
||||
return NextResponse.redirect(new URL("/", request.url));
|
||||
export async function proxy(request: NextRequest) {
|
||||
const hasSession = await isAuthenticated();
|
||||
|
||||
if (shouldRedirectDashboardRequest(request.nextUrl.pathname, hasSession)) {
|
||||
return NextResponse.redirect(new URL("/login", request.url));
|
||||
}
|
||||
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: "/dashboard/:path*",
|
||||
matcher: ["/dashboard/:path*"],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user