From b097ac4be6a0e5f60db0fa9fcf09e2e5341f532a Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 17 Feb 2025 20:24:18 -0500 Subject: [PATCH] refactor --- server/routes/index.ts | 8 +++++--- server/utils/passport.ts | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/server/routes/index.ts b/server/routes/index.ts index 204ed57487..1e4a4b60e9 100644 --- a/server/routes/index.ts +++ b/server/routes/index.ts @@ -147,10 +147,12 @@ router.get("*", shareDomains(), async (ctx, next) => { } // Redirect if subdomain is not the current team's subdomain - if (team?.subdomain && !ctx.hostname.startsWith(team.subdomain)) { + if (team?.subdomain) { const { teamSubdomain } = parseDomain(ctx.href); - ctx.redirect(ctx.href.replace(teamSubdomain, team.subdomain)); - return; + if (team?.subdomain !== teamSubdomain) { + ctx.redirect(ctx.href.replace(teamSubdomain, team.subdomain)); + return; + } } const analytics = team diff --git a/server/utils/passport.ts b/server/utils/passport.ts index 42fd05e0b6..37ff145762 100644 --- a/server/utils/passport.ts +++ b/server/utils/passport.ts @@ -127,6 +127,8 @@ export async function getTeamFromContext(ctx: Context) { } else if (domain.custom) { team = await Team.findOne({ where: { domain: domain.host } }); } else if (domain.teamSubdomain) { + // Preference is always given to the team with the subdomain currently + // otherwise we can try and find a team that previously used the subdomain. team = (await Team.findOne({ where: { subdomain: domain.teamSubdomain },