scoresaber-reloaded-v2/src/middleware.ts

23 lines
623 B
TypeScript
Raw Normal View History

2023-10-19 04:21:35 +00:00
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
export function middleware(request: NextRequest) {
2023-10-23 17:09:16 +00:00
const { pathname } = request.nextUrl;
const cookies = request.cookies;
2023-10-23 17:09:16 +00:00
const playerIdCookie = cookies.get("playerId");
2023-10-23 17:09:16 +00:00
if (pathname == "/") {
if (playerIdCookie) {
return NextResponse.redirect(
new URL(`/player/${playerIdCookie.value}/top/1`, request.url),
);
} else {
return NextResponse.redirect(new URL("/search", request.url));
}
2023-10-19 04:21:35 +00:00
}
}
export const config = {
matcher: "/((?!api|_next/static|_next/image|favicon.ico).*)",
};