Skip to content

Commit 98e26da

Browse files
committed
redirect /team/~/... to /team/<first-team-slug>/...
1 parent dc5585a commit 98e26da

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

apps/dashboard/src/middleware.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getTeams } from "@/api/team";
12
import { isLoginRequired } from "@/constants/auth";
23
import { COOKIE_ACTIVE_ACCOUNT, COOKIE_PREFIX_TOKEN } from "@/constants/cookie";
34
import { type NextRequest, NextResponse } from "next/server";
@@ -93,6 +94,18 @@ export async function middleware(request: NextRequest) {
9394
return rewrite(request, `/published-contract${pathname}`);
9495
}
9596
}
97+
98+
// redirect /team/~/... to /team/<first_team_slug>/...
99+
if (paths[0] === "team" && paths[1] === "~") {
100+
// TODO - need an API to get the first team to avoid fetching all teams
101+
const teams = await getTeams();
102+
const firstTeam = teams[0];
103+
if (firstTeam) {
104+
const modifiedPaths = [...paths];
105+
modifiedPaths[1] = firstTeam.slug;
106+
return redirect(request, `/${modifiedPaths.join("/")}`);
107+
}
108+
}
96109
// END /<address>/... case
97110
// all other cases are handled by the file system router so we just fall through
98111
}

0 commit comments

Comments
 (0)