scoresaber-reloaded-v2/src/middleware.ts
Liam cfb7d1f15d
All checks were successful
deploy / deploy (push) Successful in 58s
revert(ssr): revert locale stuff
2023-11-06 18:52:03 +00:00

23 lines
623 B
TypeScript

import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
export function middleware(request: NextRequest) {
const { pathname } = request.nextUrl;
const cookies = request.cookies;
const playerIdCookie = cookies.get("playerId");
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));
}
}
}
export const config = {
matcher: "/((?!api|_next/static|_next/image|favicon.ico).*)",
};