Ensure team authentication matches subdomain
This commit is contained in:
@ -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 <LoadingIndicator />;
|
||||
}
|
||||
|
||||
// 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 <LoadingIndicator />;
|
||||
}
|
||||
|
||||
// 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,
|
||||
|
@ -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,
|
||||
<SubdomainSignin
|
||||
|
@ -17,7 +17,7 @@ const definePlugin = new webpack.DefinePlugin({
|
||||
'process.env': {
|
||||
URL: JSON.stringify(process.env.URL),
|
||||
SLACK_KEY: JSON.stringify(process.env.SLACK_KEY),
|
||||
SUBDOMAINS_ENABLED: JSON.stringify(process.env.SUBDOMAINS_ENABLED)
|
||||
SUBDOMAINS_ENABLED: JSON.stringify(process.env.SUBDOMAINS_ENABLED === 'true')
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -36,7 +36,7 @@ productionWebpackConfig.plugins = [
|
||||
'process.env.URL': JSON.stringify(process.env.URL),
|
||||
'process.env.NODE_ENV': JSON.stringify('production'),
|
||||
'process.env.GOOGLE_ANALYTICS_ID': JSON.stringify(process.env.GOOGLE_ANALYTICS_ID),
|
||||
'process.env.SUBDOMAINS_ENABLED': JSON.stringify(process.env.SUBDOMAINS_ENABLED),
|
||||
'process.env.SUBDOMAINS_ENABLED': JSON.stringify(process.env.SUBDOMAINS_ENABLED === 'true'),
|
||||
}),
|
||||
];
|
||||
|
||||
|
Reference in New Issue
Block a user