Add support for SUBDOMAINS_ENABLED=false

This commit is contained in:
Tom Moor 2018-11-11 22:06:50 -08:00
parent 61138ff4fa
commit b3a8d34af3
6 changed files with 46 additions and 22 deletions

View File

@ -19,7 +19,7 @@ router.post('team.update', auth(), async ctx => {
const team = await Team.findById(user.teamId);
authorize(user, 'update', team);
if (process.env.SUBDOMAINS_ENABLED) {
if (process.env.SUBDOMAINS_ENABLED === 'true') {
team.subdomain = subdomain === '' ? null : subdomain;
}

View File

@ -110,7 +110,7 @@ export default function auth(options?: { required?: boolean } = {}) {
// set a transfer cookie for the access token itself and redirect
// to the teams subdomain if subdomains are enabled
if (process.env.SUBDOMAINS_ENABLED && team.subdomain) {
if (process.env.SUBDOMAINS_ENABLED === 'true' && team.subdomain) {
// get any existing sessions (teams signed in) and add this team
const existing = JSON.parse(ctx.cookies.get('sessions') || '{}');
const sessions = JSON.stringify({

View File

@ -45,7 +45,7 @@ const Team = sequelize.define(
{
getterMethods: {
url() {
if (!this.subdomain || !process.env.SUBDOMAINS_ENABLED) {
if (!this.subdomain || process.env.SUBDOMAINS_ENABLED !== 'true') {
return process.env.URL;
}

View File

@ -15,10 +15,11 @@ export const screenshotUrl = `${process.env.URL}/screenshot.png`;
type Props = {
children?: React.Node,
sessions?: Object,
sessions: Object,
loggedIn: boolean,
};
function Layout({ children, sessions }: Props) {
function Layout({ children, loggedIn, sessions }: Props) {
return (
<html lang="en">
<head>
@ -66,7 +67,7 @@ function Layout({ children, sessions }: Props) {
{'{{CSS}}'}
</head>
<Body>
<TopNavigation sessions={sessions} />
<TopNavigation sessions={sessions} loggedIn={loggedIn} />
{children}
<BottomNavigation />
</Body>

View File

@ -25,7 +25,12 @@ type Sessions = {
},
};
function TopNavigation({ sessions }: { sessions: ?Sessions }) {
type Props = {
sessions: ?Sessions,
loggedIn: boolean,
};
function TopNavigation({ sessions, loggedIn }: Props) {
const orderedSessions = sortBy(sessions, 'name');
return (
@ -47,20 +52,32 @@ function TopNavigation({ sessions }: { sessions: ?Sessions }) {
<MenuItem>
<a href={developers()}>API</a>
</MenuItem>
{orderedSessions.length ? (
<MenuItem highlighted>
<a href={developers()}>Your Teams</a>
<ol>
{orderedSessions.map(session => (
<MenuItem key={session.url}>
<a href={`${session.url}/dashboard`}>
<TeamLogo src={session.logoUrl} width={20} height={20} />
{session.name}
</a>
</MenuItem>
))}
</ol>
</MenuItem>
{loggedIn ? (
<React.Fragment>
{process.env.SUBDOMAINS_ENABLED === 'true' ? (
<MenuItem highlighted>
<a>Your Teams</a>
<ol>
{orderedSessions.map(session => (
<MenuItem key={session.url}>
<a href={`${session.url}/dashboard`}>
<TeamLogo
src={session.logoUrl}
width={20}
height={20}
/>
{session.name}
</a>
</MenuItem>
))}
</ol>
</MenuItem>
) : (
<MenuItem highlighted>
<a href="/dashboard">Dashboard</a>
</MenuItem>
)}
</React.Fragment>
) : (
<MenuItem>
<a href="/#signin">Sign In</a>

View File

@ -14,10 +14,16 @@ const sheet = new ServerStyleSheet();
export default function renderpage(ctx: Object, children: React.Node) {
const sessions = JSON.parse(ctx.cookies.get('sessions') || '{}');
const loggedIn = !!(
ctx.cookies.get('accessToken') || Object.keys(sessions).length
);
const html = ReactDOMServer.renderToString(
<StyleSheetManager sheet={sheet.instance}>
<ThemeProvider theme={theme}>
<Layout sessions={sessions}>{children}</Layout>
<Layout sessions={sessions} loggedIn={loggedIn}>
{children}
</Layout>
</ThemeProvider>
</StyleSheetManager>
);