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;
|
2023-10-24 06:47:11 +00:00
|
|
|
const cookies = request.cookies;
|
2023-10-23 17:09:16 +00:00
|
|
|
|
2023-10-24 06:47:11 +00:00
|
|
|
const playerIdCookie = cookies.get("playerId");
|
2023-10-23 17:09:16 +00:00
|
|
|
if (pathname == "/") {
|
2023-10-24 06:47:11 +00:00
|
|
|
if (playerIdCookie) {
|
|
|
|
return NextResponse.redirect(
|
2023-10-24 11:56:28 +00:00
|
|
|
new URL(`/player/${playerIdCookie.value}/top/1`, request.url),
|
2023-10-24 06:47:11 +00:00
|
|
|
);
|
|
|
|
} 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).*)",
|
|
|
|
};
|