Skip to content

Commit d288f46

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

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
@@ -3,6 +3,7 @@ import { COOKIE_ACTIVE_ACCOUNT, COOKIE_PREFIX_TOKEN } from "@/constants/cookie";
33
import { type NextRequest, NextResponse } from "next/server";
44
import { getAddress } from "thirdweb";
55
import { getChainMetadata } from "thirdweb/chains";
6+
import { getTeams } from "./@/api/team";
67
import { defineDashboardChain } from "./lib/defineDashboardChain";
78

89
// ignore assets, api - only intercept page routes
@@ -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)