Attempt to provision subdomain on team create
This commit is contained in:
@ -27,7 +27,9 @@ const Auth = observer(({ auth, children }: Props) => {
|
|||||||
// Check the current origin against the teams url, if they differ we need to
|
// Check the current origin against the teams url, if they differ we need to
|
||||||
// redirect to the canonical subdomain for this team
|
// redirect to the canonical subdomain for this team
|
||||||
if (window.location.origin !== team.url) {
|
if (window.location.origin !== team.url) {
|
||||||
window.location.href = `${team.url}${window.location.pathname}`;
|
const redirectTo = `${team.url}${window.location.pathname}`;
|
||||||
|
console.warn(`Redirecting to ${redirectTo}…`);
|
||||||
|
window.location.href = redirectTo;
|
||||||
return <LoadingIndicator />;
|
return <LoadingIndicator />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import Router from 'koa-router';
|
import Router from 'koa-router';
|
||||||
import addMonths from 'date-fns/add_months';
|
import addMonths from 'date-fns/add_months';
|
||||||
import { stripSubdomain } from '../utils/domains';
|
import { stripSubdomain } from '../../shared/utils/domains';
|
||||||
import { capitalize } from 'lodash';
|
import { capitalize } from 'lodash';
|
||||||
import { OAuth2Client } from 'google-auth-library';
|
import { OAuth2Client } from 'google-auth-library';
|
||||||
import { User, Team } from '../models';
|
import { User, Team } from '../models';
|
||||||
@ -53,7 +53,8 @@ router.get('google.callback', async ctx => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const googleId = profile.data.hd;
|
const googleId = profile.data.hd;
|
||||||
const teamName = capitalize(profile.data.hd.split('.')[0]);
|
const hostname = profile.data.hd.split('.')[0];
|
||||||
|
const teamName = capitalize(hostname);
|
||||||
|
|
||||||
// attempt to get logo from Clearbit API. If one doesn't exist then
|
// attempt to get logo from Clearbit API. If one doesn't exist then
|
||||||
// fall back to using tiley to generate a placeholder logo
|
// fall back to using tiley to generate a placeholder logo
|
||||||
@ -93,6 +94,13 @@ router.get('google.callback', async ctx => {
|
|||||||
|
|
||||||
if (isFirstUser) {
|
if (isFirstUser) {
|
||||||
await team.createFirstCollection(user.id);
|
await team.createFirstCollection(user.id);
|
||||||
|
|
||||||
|
// attempt to give the new team a subdomain based on google hosted domain
|
||||||
|
try {
|
||||||
|
await team.update({ subdomain: hostname });
|
||||||
|
} catch (err) {
|
||||||
|
// subdomain was invalid or already used
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// not awaiting the promise here so that the request is not blocked
|
// not awaiting the promise here so that the request is not blocked
|
||||||
|
@ -4,8 +4,8 @@ import auth from '../middlewares/authentication';
|
|||||||
import addHours from 'date-fns/add_hours';
|
import addHours from 'date-fns/add_hours';
|
||||||
import addMonths from 'date-fns/add_months';
|
import addMonths from 'date-fns/add_months';
|
||||||
import { slackAuth } from '../../shared/utils/routeHelpers';
|
import { slackAuth } from '../../shared/utils/routeHelpers';
|
||||||
|
import { stripSubdomain } from '../../shared/utils/domains';
|
||||||
import { Authentication, Integration, User, Team } from '../models';
|
import { Authentication, Integration, User, Team } from '../models';
|
||||||
import { stripSubdomain } from '../utils/domains';
|
|
||||||
import * as Slack from '../slack';
|
import * as Slack from '../slack';
|
||||||
|
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
@ -63,6 +63,13 @@ router.get('slack.callback', async ctx => {
|
|||||||
|
|
||||||
if (isFirstUser) {
|
if (isFirstUser) {
|
||||||
await team.createFirstCollection(user.id);
|
await team.createFirstCollection(user.id);
|
||||||
|
|
||||||
|
// attempt to give the new team the same subdomain as they use on slack
|
||||||
|
try {
|
||||||
|
await team.update({ subdomain: data.team.domain });
|
||||||
|
} catch (err) {
|
||||||
|
// subdomain was invalid or already used
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// not awaiting the promise here so that the request is not blocked
|
// not awaiting the promise here so that the request is not blocked
|
||||||
|
@ -3,7 +3,7 @@ import uuid from 'uuid';
|
|||||||
import { URL } from 'url';
|
import { URL } from 'url';
|
||||||
import { DataTypes, sequelize, Op } from '../sequelize';
|
import { DataTypes, sequelize, Op } from '../sequelize';
|
||||||
import { publicS3Endpoint, uploadToS3FromUrl } from '../utils/s3';
|
import { publicS3Endpoint, uploadToS3FromUrl } from '../utils/s3';
|
||||||
import { RESERVED_SUBDOMAINS } from '../utils/domains';
|
import { RESERVED_SUBDOMAINS } from '../../shared/utils/domains';
|
||||||
import Collection from './Collection';
|
import Collection from './Collection';
|
||||||
import User from './User';
|
import User from './User';
|
||||||
|
|
||||||
|
@ -10,26 +10,57 @@ export function stripSubdomain(hostname: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const RESERVED_SUBDOMAINS = [
|
export const RESERVED_SUBDOMAINS = [
|
||||||
|
'about',
|
||||||
|
'account',
|
||||||
'admin',
|
'admin',
|
||||||
|
'advertising',
|
||||||
'api',
|
'api',
|
||||||
|
'assets',
|
||||||
|
'archive',
|
||||||
'beta',
|
'beta',
|
||||||
|
'billing',
|
||||||
'blog',
|
'blog',
|
||||||
|
'cache',
|
||||||
'cdn',
|
'cdn',
|
||||||
|
'code',
|
||||||
'community',
|
'community',
|
||||||
|
'dashboard',
|
||||||
'developer',
|
'developer',
|
||||||
|
'developers',
|
||||||
'forum',
|
'forum',
|
||||||
'help',
|
'help',
|
||||||
|
'home',
|
||||||
|
'http',
|
||||||
|
'https',
|
||||||
'imap',
|
'imap',
|
||||||
'localhost',
|
'localhost',
|
||||||
'mail',
|
'mail',
|
||||||
|
'mobile',
|
||||||
|
'news',
|
||||||
|
'newsletter',
|
||||||
'ns1',
|
'ns1',
|
||||||
'ns2',
|
'ns2',
|
||||||
'ns3',
|
'ns3',
|
||||||
'ns4',
|
'ns4',
|
||||||
|
'password',
|
||||||
|
'profile',
|
||||||
|
'sandbox',
|
||||||
|
'script',
|
||||||
|
'scripts',
|
||||||
|
'setup',
|
||||||
|
'signin',
|
||||||
|
'signup',
|
||||||
'smtp',
|
'smtp',
|
||||||
'support',
|
'support',
|
||||||
'status',
|
'status',
|
||||||
'static',
|
'static',
|
||||||
|
'stats',
|
||||||
'test',
|
'test',
|
||||||
|
'update',
|
||||||
|
'updates',
|
||||||
'www',
|
'www',
|
||||||
|
'www1',
|
||||||
|
'www2',
|
||||||
|
'www3',
|
||||||
|
'www4',
|
||||||
];
|
];
|
Reference in New Issue
Block a user