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">
<FormattedMessage id="label.realtime" defaultMessage="Realtime" />
</Link>
{!process.env.isCloudMode && (
{!process.env.isAdminDisabled && (
<Link href="/settings">
<FormattedMessage id="label.settings" defaultMessage="Settings" />
</Link>

View File

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

View File

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

View File

@ -2,7 +2,11 @@ import React from 'react';
import Layout from 'components/layout/Layout';
import { FormattedMessage } from 'react-intl';
export default function Custom404() {
export default function Custom404({ pageDisabled }) {
if (pageDisabled) {
return null;
}
return (
<Layout>
<div className="row justify-content-center">
@ -13,3 +17,11 @@ export default function Custom404() {
</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 useUser from 'hooks/useUser';
export default function ConsolePage({ enabled }) {
export default function ConsolePage({ enabled, pageDisabled }) {
const { loading } = useRequireLogin();
const { user } = useUser();
if (loading || !enabled || !user?.isAdmin) {
if (pageDisabled || loading || !enabled || !user?.isAdmin) {
return null;
}
@ -21,6 +21,9 @@ export default function ConsolePage({ enabled }) {
export async function getServerSideProps() {
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 useUser from 'hooks/useUser';
export default function DashboardPage() {
export default function DashboardPage({ pageDisabled }) {
const {
query: { id },
isReady,
@ -14,7 +14,7 @@ export default function DashboardPage() {
const { loading } = useRequireLogin();
const user = useUser();
if (!user || !isReady || loading) {
if (pageDisabled || !user || !isReady || loading) {
return null;
}
@ -26,3 +26,11 @@ export default function DashboardPage() {
</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 LoginForm from 'components/forms/LoginForm';
export default function LoginPage({ loginDisabled }) {
if (loginDisabled) {
export default function LoginPage({ pageDisabled }) {
if (pageDisabled) {
return null;
}
@ -16,6 +16,9 @@ export default function LoginPage({ loginDisabled }) {
export async function getServerSideProps() {
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 useRequireLogin from 'hooks/useRequireLogin';
export default function RealtimePage() {
export default function RealtimePage({ pageDisabled }) {
const { loading } = useRequireLogin();
if (loading) {
if (pageDisabled || loading) {
return null;
}
@ -16,3 +16,11 @@ export default function RealtimePage() {
</Layout>
);
}
export async function getServerSideProps() {
return {
props: {
pageDisabled: !!process.env.DISABLE_UI,
},
};
}

View File

@ -1,3 +1,11 @@
import Index from './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 useRequireLogin from 'hooks/useRequireLogin';
export default function SettingsPage() {
export default function SettingsPage({ pageDisabled }) {
const { loading } = useRequireLogin();
if (process.env.isCloudMode || loading) {
if (pageDisabled || loading) {
return null;
}
@ -16,3 +16,11 @@ export default function SettingsPage() {
</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';
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 useShareToken from 'hooks/useShareToken';
export default function SharePage() {
export default function SharePage({ pageDisabled }) {
const router = useRouter();
const { id } = router.query;
const shareId = id?.[0];
const shareToken = useShareToken(shareId);
if (!shareToken) {
if (pageDisabled || !shareToken) {
return null;
}
@ -20,3 +20,11 @@ export default function SharePage() {
</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 useRequireLogin from 'hooks/useRequireLogin';
export default function DetailsPage() {
export default function DetailsPage({ pageDisabled }) {
const { loading } = useRequireLogin();
const router = useRouter();
const { id } = router.query;
if (!id || loading) {
if (pageDisabled || !id || loading) {
return null;
}
@ -21,3 +21,11 @@ export default function DetailsPage() {
</Layout>
);
}
export async function getServerSideProps() {
return {
props: {
pageDisabled: !!process.env.DISABLE_UI,
},
};
}