diff --git a/app/components/Auth.js b/app/components/Auth.js
index 2a6b33ac1..268dae30e 100644
--- a/app/components/Auth.js
+++ b/app/components/Auth.js
@@ -19,15 +19,28 @@ let authenticatedStores;
const Auth = observer(({ auth, children }: Props) => {
if (auth.authenticated) {
const { user, team } = auth;
+ const { hostname } = window.location;
if (!team || !user) {
return ;
}
+ // If we're authenticated but viewing a subdomain that doesn't match the
+ // authenticated team then kick the user to the teams subdomain.
+ // www is a special case, as always
+ if (
+ process.env.SUBDOMAINS_ENABLED &&
+ team.subdomain &&
+ !hostname.startsWith(`${team.subdomain}.`) &&
+ !hostname.startsWith('www.')
+ ) {
+ window.location.href = `${team.url}${window.location.pathname}`;
+ return ;
+ }
+
// Only initialize stores once. Kept in global scope because otherwise they
// will get overridden on route change
if (!authenticatedStores) {
- // Stores for authenticated user
authenticatedStores = {
integrations: new IntegrationsStore({
ui: stores.ui,
diff --git a/server/routes.js b/server/routes.js
index 691399cb8..926f55417 100644
--- a/server/routes.js
+++ b/server/routes.js
@@ -86,7 +86,7 @@ router.get('/', async ctx => {
const team = await Team.find({
where: { subdomain },
});
- if (team && process.env.SUBDOMAINS_ENABLED) {
+ if (team && process.env.SUBDOMAINS_ENABLED === 'true') {
return renderpage(
ctx,