add DISABLE_UI, DISABLE_ADMIN

This commit is contained in:
Brian Cao 2022-10-27 12:14:34 -07:00
parent 736f06442c
commit 99c975c329
13 changed files with 94 additions and 20 deletions

View File

@ -38,7 +38,7 @@ export default function Header() {
<Link href="/realtime"> <Link href="/realtime">
<FormattedMessage id="label.realtime" defaultMessage="Realtime" /> <FormattedMessage id="label.realtime" defaultMessage="Realtime" />
</Link> </Link>
{!process.env.isCloudMode && ( {!process.env.isAdminDisabled && (
<Link href="/settings"> <Link href="/settings">
<FormattedMessage id="label.settings" defaultMessage="Settings" /> <FormattedMessage id="label.settings" defaultMessage="Settings" />
</Link> </Link>

View File

@ -28,7 +28,7 @@ export default function UserButton() {
{ {
label: <FormattedMessage id="label.profile" defaultMessage="Profile" />, label: <FormattedMessage id="label.profile" defaultMessage="Profile" />,
value: 'profile', value: 'profile',
hidden: process.env.isCloudMode, hidden: process.env.isAdminDisabled,
}, },
{ label: <FormattedMessage id="label.logout" defaultMessage="Logout" />, value: 'logout' }, { label: <FormattedMessage id="label.logout" defaultMessage="Logout" />, value: 'logout' },
]; ];

View File

@ -36,7 +36,7 @@ module.exports = {
env: { env: {
currentVersion: pkg.version, currentVersion: pkg.version,
isProduction: process.env.NODE_ENV === 'production', isProduction: process.env.NODE_ENV === 'production',
isCloudMode: process.env.CLOUD_MODE, isAdminDisabled: process.env.DISABLE_ADMIN,
}, },
basePath: process.env.BASE_PATH, basePath: process.env.BASE_PATH,
output: 'standalone', output: 'standalone',

View File

@ -2,7 +2,11 @@ import React from 'react';
import Layout from 'components/layout/Layout'; import Layout from 'components/layout/Layout';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage } from 'react-intl';
export default function Custom404() { export default function Custom404({ pageDisabled }) {
if (pageDisabled) {
return null;
}
return ( return (
<Layout> <Layout>
<div className="row justify-content-center"> <div className="row justify-content-center">
@ -13,3 +17,11 @@ export default function Custom404() {
</Layout> </Layout>
); );
} }
export async function getServerSideProps() {
return {
props: {
pageDisabled: !!process.env.DISABLE_UI,
},
};
}

View File

@ -4,11 +4,11 @@ import TestConsole from 'components/pages/TestConsole';
import useRequireLogin from 'hooks/useRequireLogin'; import useRequireLogin from 'hooks/useRequireLogin';
import useUser from 'hooks/useUser'; import useUser from 'hooks/useUser';
export default function ConsolePage({ enabled }) { export default function ConsolePage({ enabled, pageDisabled }) {
const { loading } = useRequireLogin(); const { loading } = useRequireLogin();
const { user } = useUser(); const { user } = useUser();
if (loading || !enabled || !user?.isAdmin) { if (pageDisabled || loading || !enabled || !user?.isAdmin) {
return null; return null;
} }
@ -21,6 +21,9 @@ export default function ConsolePage({ enabled }) {
export async function getServerSideProps() { export async function getServerSideProps() {
return { return {
props: { enabled: !!process.env.ENABLE_TEST_CONSOLE }, props: {
pageDisabled: !!process.env.DISABLE_UI,
enabled: !!process.env.ENABLE_TEST_CONSOLE,
},
}; };
} }

View File

@ -5,7 +5,7 @@ import useRequireLogin from 'hooks/useRequireLogin';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import useUser from 'hooks/useUser'; import useUser from 'hooks/useUser';
export default function DashboardPage() { export default function DashboardPage({ pageDisabled }) {
const { const {
query: { id }, query: { id },
isReady, isReady,
@ -14,7 +14,7 @@ export default function DashboardPage() {
const { loading } = useRequireLogin(); const { loading } = useRequireLogin();
const user = useUser(); const user = useUser();
if (!user || !isReady || loading) { if (pageDisabled || !user || !isReady || loading) {
return null; return null;
} }
@ -26,3 +26,11 @@ export default function DashboardPage() {
</Layout> </Layout>
); );
} }
export async function getServerSideProps() {
return {
props: {
pageDisabled: !!process.env.DISABLE_UI,
},
};
}

View File

@ -2,8 +2,8 @@ import React from 'react';
import Layout from 'components/layout/Layout'; import Layout from 'components/layout/Layout';
import LoginForm from 'components/forms/LoginForm'; import LoginForm from 'components/forms/LoginForm';
export default function LoginPage({ loginDisabled }) { export default function LoginPage({ pageDisabled }) {
if (loginDisabled) { if (pageDisabled) {
return null; return null;
} }
@ -16,6 +16,9 @@ export default function LoginPage({ loginDisabled }) {
export async function getServerSideProps() { export async function getServerSideProps() {
return { return {
props: { loginDisabled: !!process.env.DISABLE_LOGIN || !!process.env.isCloudMode }, props: {
pageDisabled:
!!process.env.DISABLE_LOGIN || !!process.env.DISABLE_UI || !!process.env.isAdminDisabled,
},
}; };
} }

View File

@ -3,10 +3,10 @@ import Layout from 'components/layout/Layout';
import RealtimeDashboard from 'components/pages/RealtimeDashboard'; import RealtimeDashboard from 'components/pages/RealtimeDashboard';
import useRequireLogin from 'hooks/useRequireLogin'; import useRequireLogin from 'hooks/useRequireLogin';
export default function RealtimePage() { export default function RealtimePage({ pageDisabled }) {
const { loading } = useRequireLogin(); const { loading } = useRequireLogin();
if (loading) { if (pageDisabled || loading) {
return null; return null;
} }
@ -16,3 +16,11 @@ export default function RealtimePage() {
</Layout> </Layout>
); );
} }
export async function getServerSideProps() {
return {
props: {
pageDisabled: !!process.env.DISABLE_UI,
},
};
}

View File

@ -1,3 +1,11 @@
import Index from './index'; import Index from './index';
export default Index; export default Index;
export async function getServerSideProps() {
return {
props: {
pageDisabled: !!process.env.DISABLE_UI,
},
};
}

View File

@ -3,10 +3,10 @@ import Layout from 'components/layout/Layout';
import Settings from 'components/pages/Settings'; import Settings from 'components/pages/Settings';
import useRequireLogin from 'hooks/useRequireLogin'; import useRequireLogin from 'hooks/useRequireLogin';
export default function SettingsPage() { export default function SettingsPage({ pageDisabled }) {
const { loading } = useRequireLogin(); const { loading } = useRequireLogin();
if (process.env.isCloudMode || loading) { if (pageDisabled || loading) {
return null; return null;
} }
@ -16,3 +16,11 @@ export default function SettingsPage() {
</Layout> </Layout>
); );
} }
export async function getServerSideProps() {
return {
props: {
pageDisabled: !!process.env.DISABLE_UI || !!process.env.isAdminDisabled,
},
};
}

View File

@ -1,3 +1,11 @@
import Index from './index'; import Index from './index';
export default Index; export default Index;
export async function getServerSideProps() {
return {
props: {
pageDisabled: !!process.env.DISABLE_UI,
},
};
}

View File

@ -4,13 +4,13 @@ import Layout from 'components/layout/Layout';
import WebsiteDetails from 'components/pages/WebsiteDetails'; import WebsiteDetails from 'components/pages/WebsiteDetails';
import useShareToken from 'hooks/useShareToken'; import useShareToken from 'hooks/useShareToken';
export default function SharePage() { export default function SharePage({ pageDisabled }) {
const router = useRouter(); const router = useRouter();
const { id } = router.query; const { id } = router.query;
const shareId = id?.[0]; const shareId = id?.[0];
const shareToken = useShareToken(shareId); const shareToken = useShareToken(shareId);
if (!shareToken) { if (pageDisabled || !shareToken) {
return null; return null;
} }
@ -20,3 +20,11 @@ export default function SharePage() {
</Layout> </Layout>
); );
} }
export async function getServerSideProps() {
return {
props: {
pageDisabled: !!process.env.DISABLE_UI,
},
};
}

View File

@ -4,12 +4,12 @@ import Layout from 'components/layout/Layout';
import WebsiteDetails from 'components/pages/WebsiteDetails'; import WebsiteDetails from 'components/pages/WebsiteDetails';
import useRequireLogin from 'hooks/useRequireLogin'; import useRequireLogin from 'hooks/useRequireLogin';
export default function DetailsPage() { export default function DetailsPage({ pageDisabled }) {
const { loading } = useRequireLogin(); const { loading } = useRequireLogin();
const router = useRouter(); const router = useRouter();
const { id } = router.query; const { id } = router.query;
if (!id || loading) { if (pageDisabled || !id || loading) {
return null; return null;
} }
@ -21,3 +21,11 @@ export default function DetailsPage() {
</Layout> </Layout>
); );
} }
export async function getServerSideProps() {
return {
props: {
pageDisabled: !!process.env.DISABLE_UI,
},
};
}