Skip to content

Commit 761cbf1

Browse files
authored
feat(ui): add runtime config for app and company names (#1272)
1 parent 728867d commit 761cbf1

File tree

21 files changed

+87
-60
lines changed

21 files changed

+87
-60
lines changed

apps/beeai-ui/.env.example

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ API_URL=
55
# All feature flags default to false
66
FEATURE_FLAGS='{"Variables":true,"Providers":true,"ModelProviders":true,"MCPOAuth":true,"MCP":true}'
77

8+
# Default: 'BeeAI'
9+
APP_NAME=
10+
11+
# Default: undefined
12+
COMPANY_NAME=
13+
814
# Default: 'http://localhost:3000'
915
NEXT_PUBLIC_BASE_URL=
1016

1117
# Default: ''
1218
NEXT_PUBLIC_BASE_PATH=
1319

14-
# Default: 'BeeAI'
15-
NEXT_PUBLIC_APP_NAME=
16-
17-
# Default: undefined
18-
NEXT_PUBLIC_COMPANY_NAME=
19-
2020
# Default: '/bee.svg'
2121
NEXT_PUBLIC_APP_FAVICON_SVG=
2222

apps/beeai-ui/src/api/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import type { Middleware } from 'openapi-fetch';
77
import createClient from 'openapi-fetch';
88

99
import { ensureToken } from '#app/(auth)/rsc.tsx';
10+
import { runtimeConfig } from '#contexts/App/runtime-config.ts';
1011
import { getBaseUrl } from '#utils/api/getBaseUrl.ts';
11-
import { OIDC_ENABLED } from '#utils/constants.ts';
1212

1313
import type { paths } from './schema';
1414

1515
const authMiddleware: Middleware = {
1616
async onRequest({ request }) {
1717
let accessToken: string | undefined = undefined;
1818

19-
if (OIDC_ENABLED) {
19+
if (runtimeConfig.isAuthEnabled) {
2020
const token = await ensureToken(request);
2121

2222
if (token?.access_token) {

apps/beeai-ui/src/app/(auth)/auth.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import NextAuth from 'next-auth';
77
import type { Provider } from 'next-auth/providers';
88

99
import { getProviderConstructor } from '#app/(auth)/providers/providers.ts';
10-
import { OIDC_ENABLED } from '#utils/constants.ts';
10+
import { runtimeConfig } from '#contexts/App/runtime-config.ts';
1111
import { routes } from '#utils/router.ts';
1212

1313
import type { ProviderConfig } from './types';
@@ -19,7 +19,9 @@ const providers: Provider[] = [];
1919

2020
export const AUTH_COOKIE_NAME = 'beeai-platform';
2121

22-
if (OIDC_ENABLED) {
22+
const { isAuthEnabled } = runtimeConfig;
23+
24+
if (isAuthEnabled) {
2325
try {
2426
const providersJson = process.env.OIDC_PROVIDERS;
2527
if (!providersJson) {
@@ -68,7 +70,7 @@ export const { handlers, signIn, signOut, auth } = NextAuth({
6870
session: { strategy: 'jwt' },
6971
trustHost: true,
7072
// Prevents nextauth errors when authentication is disabled and NEXTAUTH_SECRET is not provided
71-
secret: OIDC_ENABLED ? process.env.NEXTAUTH_SECRET : 'dummy_secret',
73+
secret: isAuthEnabled ? process.env.NEXTAUTH_SECRET : 'dummy_secret',
7274
cookies: {
7375
sessionToken: {
7476
name: AUTH_COOKIE_NAME,
@@ -81,7 +83,7 @@ export const { handlers, signIn, signOut, auth } = NextAuth({
8183
},
8284
callbacks: {
8385
authorized: ({ auth }) => {
84-
return OIDC_ENABLED ? Boolean(auth) : true;
86+
return isAuthEnabled ? Boolean(auth) : true;
8587
},
8688
jwt: async ({ token, account, trigger, session }) => {
8789
if (trigger === 'update') {

apps/beeai-ui/src/app/(auth)/rsc.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
import { cookies } from 'next/headers';
77
import { getToken } from 'next-auth/jwt';
88

9-
import { OIDC_ENABLED } from '#utils/constants.ts';
9+
import { runtimeConfig } from '#contexts/App/runtime-config.ts';
1010

1111
import { auth, AUTH_COOKIE_NAME } from './auth';
1212

1313
export const ensureToken = async (request: Request) => {
14-
if (!OIDC_ENABLED) {
14+
if (!runtimeConfig.isAuthEnabled) {
1515
return null;
1616
}
1717

apps/beeai-ui/src/app/api/[...path]/route.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { redirect } from 'next/navigation';
77
import type { NextRequest } from 'next/server';
88

99
import { ensureToken } from '#app/(auth)/rsc.tsx';
10-
import { API_URL, OIDC_ENABLED } from '#utils/constants.ts';
10+
import { runtimeConfig } from '#contexts/App/runtime-config.ts';
11+
import { API_URL } from '#utils/constants.ts';
1112
import { routes } from '#utils/router.ts';
1213

1314
import { transformAgentManifestBody } from './body-transformers';
@@ -31,7 +32,7 @@ async function handler(request: NextRequest, context: RouteContext) {
3132
}
3233
targetUrl += search;
3334

34-
if (OIDC_ENABLED) {
35+
if (runtimeConfig.isAuthEnabled) {
3536
const token = await ensureToken(request);
3637

3738
if (!token) {

apps/beeai-ui/src/app/layout.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import '#styles/style.scss';
88
import type { Metadata } from 'next';
99

1010
import { AppProvider } from '#contexts/App/AppProvider.tsx';
11+
import { runtimeConfig } from '#contexts/App/runtime-config.ts';
1112
import Providers from '#providers.tsx';
12-
import { APP_FAVICON_SVG, APP_NAME, BASE_PATH, OIDC_ENABLED } from '#utils/constants.ts';
13-
import { parseFeatureFlags } from '#utils/feature-flags.ts';
13+
import { APP_FAVICON_SVG, BASE_PATH } from '#utils/constants.ts';
1414

1515
const darkModeScript = `
1616
(() => {
@@ -34,7 +34,7 @@ const darkModeScript = `
3434
const icon = `${BASE_PATH}${APP_FAVICON_SVG}`;
3535

3636
export const metadata: Metadata = {
37-
title: APP_NAME,
37+
title: runtimeConfig.appName,
3838
icons: {
3939
icon: icon,
4040
shortcut: icon,
@@ -52,7 +52,7 @@ export default function RootLayout({
5252
<script dangerouslySetInnerHTML={{ __html: darkModeScript }} />
5353
</head>
5454
<body>
55-
<AppProvider featureFlags={parseFeatureFlags(process.env.FEATURE_FLAGS)} isAuthEnabled={OIDC_ENABLED}>
55+
<AppProvider config={runtimeConfig}>
5656
<Providers>{children}</Providers>
5757
</AppProvider>
5858
</body>

apps/beeai-ui/src/components/AppHeader/AppName.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { APP_NAME, COMPANY_NAME } from '#utils/constants.ts';
6+
import { useApp } from '#contexts/App/index.ts';
77

88
import classes from './AppName.module.scss';
99

1010
export function AppName() {
11+
const {
12+
config: { appName, companyName },
13+
} = useApp();
14+
1115
return (
1216
<span className={classes.root}>
13-
{COMPANY_NAME && <span className={classes.companyName}>{COMPANY_NAME}</span>}
17+
{companyName && <span className={classes.companyName}>{companyName}</span>}
1418

15-
<span className={classes.appName}>{APP_NAME}</span>
19+
<span className={classes.appName}>{appName}</span>
1620
</span>
1721
);
1822
}

apps/beeai-ui/src/components/UserNav/UserNav.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ import classes from './UserNav.module.scss';
2222

2323
export function UserNav() {
2424
const { transitionTo } = useRouteTransition();
25-
const { setNavigationOpen, isAuthEnabled } = useApp();
25+
const {
26+
setNavigationOpen,
27+
config: { isAuthEnabled },
28+
} = useApp();
2629
const isMaxUp = useBreakpointUp('max');
2730

2831
const items: NavItem[] = useMemo(

apps/beeai-ui/src/contexts/App/AppProvider.tsx

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@
77
import type { PropsWithChildren } from 'react';
88
import { useCallback, useMemo, useState } from 'react';
99

10-
import type { FeatureFlags } from '#utils/feature-flags.ts';
11-
1210
import { AppContext } from './app-context';
13-
import type { SidePanelVariant } from './types';
11+
import type { RuntimeConfig, SidePanelVariant } from './types';
1412

1513
interface Props {
16-
featureFlags: FeatureFlags;
17-
isAuthEnabled: boolean;
14+
config: RuntimeConfig;
1815
}
1916

20-
export function AppProvider({ featureFlags, isAuthEnabled, children }: PropsWithChildren<Props>) {
17+
export function AppProvider({ config, children }: PropsWithChildren<Props>) {
2118
const [navigationOpen, setNavigationOpen] = useState(false);
2219
const [closeNavOnClickOutside, setCloseNavOnClickOutside] = useState(false);
2320
const [activeSidePanel, setActiveSidePanel] = useState<SidePanelVariant | null>(null);
@@ -32,25 +29,16 @@ export function AppProvider({ featureFlags, isAuthEnabled, children }: PropsWith
3229

3330
const contextValue = useMemo(
3431
() => ({
35-
featureFlags,
32+
config,
3633
navigationOpen,
3734
closeNavOnClickOutside,
3835
activeSidePanel,
39-
isAuthEnabled,
4036
setNavigationOpen,
4137
setCloseNavOnClickOutside,
4238
openSidePanel,
4339
closeSidePanel,
4440
}),
45-
[
46-
featureFlags,
47-
navigationOpen,
48-
closeNavOnClickOutside,
49-
activeSidePanel,
50-
isAuthEnabled,
51-
openSidePanel,
52-
closeSidePanel,
53-
],
41+
[config, navigationOpen, closeNavOnClickOutside, activeSidePanel, openSidePanel, closeSidePanel],
5442
);
5543

5644
return <AppContext.Provider value={contextValue}>{children}</AppContext.Provider>;

apps/beeai-ui/src/contexts/App/app-context.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@
77

88
import { createContext, type Dispatch, type SetStateAction } from 'react';
99

10-
import type { FeatureFlags } from '#utils/feature-flags.ts';
11-
12-
import type { SidePanelVariant } from './types';
10+
import type { RuntimeConfig, SidePanelVariant } from './types';
1311

1412
export const AppContext = createContext<AppContextValue | undefined>(undefined);
1513

1614
interface AppContextValue {
17-
featureFlags: FeatureFlags;
15+
config: RuntimeConfig;
1816
navigationOpen: boolean;
1917
closeNavOnClickOutside: boolean;
2018
activeSidePanel: SidePanelVariant | null;
21-
isAuthEnabled: boolean;
2219
setNavigationOpen: Dispatch<SetStateAction<boolean>>;
2320
setCloseNavOnClickOutside: Dispatch<SetStateAction<boolean>>;
2421
openSidePanel: (variant: SidePanelVariant) => void;

0 commit comments

Comments
 (0)