Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions apps/dashboard/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -93,6 +94,18 @@ export async function middleware(request: NextRequest) {
return rewrite(request, `/published-contract${pathname}`);
}
}

// redirect /team/~/... to /team/<first_team_slug>/...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can't this just be /team? why do we need the extra /~ in there?

Copy link
Member Author

@MananTank MananTank Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to have /team/ instead of /team/~/

  • That breaks the usual format - it should be /team/<team-slug>/<...otherSlugs>
  • We'll have to determine if otherSlugs[0] is not a valid team slug and then insert the first team's slug before them

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you want to allow the deep-linking to something inside the default team - okay

if (paths[0] === "team" && paths[1] === "~") {
// TODO - need an API to get the first team to avoid fetching all teams
const teams = await getTeams();
Comment on lines +100 to +101
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we need a getDefaultTeam

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a blocker however

const firstTeam = teams[0];
if (firstTeam) {
const modifiedPaths = [...paths];
modifiedPaths[1] = firstTeam.slug;
return redirect(request, `/${modifiedPaths.join("/")}`);
}
}
// END /<address>/... case
// all other cases are handled by the file system router so we just fall through
}
Expand Down
Loading