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 },