diff --git a/apps/dashboard/src/middleware.ts b/apps/dashboard/src/middleware.ts index 1fd94957975..d74965c8a17 100644 --- a/apps/dashboard/src/middleware.ts +++ b/apps/dashboard/src/middleware.ts @@ -1,3 +1,4 @@ +import { getTeams } from "@/api/team"; import { isLoginRequired } from "@/constants/auth"; import { COOKIE_ACTIVE_ACCOUNT, COOKIE_PREFIX_TOKEN } from "@/constants/cookie"; import { type NextRequest, NextResponse } from "next/server"; @@ -93,6 +94,18 @@ export async function middleware(request: NextRequest) { return rewrite(request, `/published-contract${pathname}`); } } + + // redirect /team/~/... to /team//... + if (paths[0] === "team" && paths[1] === "~") { + // TODO - need an API to get the first team to avoid fetching all teams + const teams = await getTeams(); + const firstTeam = teams[0]; + if (firstTeam) { + const modifiedPaths = [...paths]; + modifiedPaths[1] = firstTeam.slug; + return redirect(request, `/${modifiedPaths.join("/")}`); + } + } // END /
/... case // all other cases are handled by the file system router so we just fall through }