@lobehub/chat 0.147.15 → 0.147.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/package.json +1 -1
  3. package/src/app/api/auth/[...nextauth]/route.ts +1 -1
  4. package/src/app/chat/(desktop)/features/ChatInput/Footer/index.tsx +7 -1
  5. package/src/app/chat/(desktop)/features/ChatInput/TextArea.tsx +7 -1
  6. package/src/app/layout.tsx +2 -2
  7. package/src/config/server/app.ts +0 -18
  8. package/src/config/server/auth.ts +71 -0
  9. package/src/config/server/index.ts +3 -1
  10. package/src/layout/AuthProvider/NextAuth/index.tsx +10 -0
  11. package/src/layout/AuthProvider/index.tsx +3 -7
  12. package/src/layout/DefaultLayout/Desktop/SideBar/Avatar.tsx +11 -0
  13. package/src/layout/{GlobalLayout → DefaultLayout}/Desktop/SideBar/index.tsx +2 -2
  14. package/src/layout/{GlobalLayout/Mobile/Client.tsx → DefaultLayout/Mobile/index.tsx} +2 -0
  15. package/src/layout/DefaultLayout/index.ts +2 -0
  16. package/src/layout/{GlobalLayout/Desktop/index.tsx → routes/Desktop.tsx} +5 -3
  17. package/src/layout/{GlobalLayout/Mobile/index.tsx → routes/Mobile.tsx} +3 -4
  18. package/src/layout/{GlobalLayout → routes}/index.tsx +2 -2
  19. package/src/{app/api/auth/next-auth.ts → libs/next-auth/index.ts} +1 -1
  20. package/src/middleware.ts +1 -1
  21. /package/src/layout/{GlobalLayout → DefaultLayout}/Desktop/SideBar/BottomActions.tsx +0 -0
  22. /package/src/layout/{GlobalLayout → DefaultLayout}/Desktop/SideBar/TopActions.tsx +0 -0
  23. /package/src/layout/{GlobalLayout/Desktop/Client.tsx → DefaultLayout/Desktop/index.tsx} +0 -0
  24. /package/src/{app/api/auth → libs/next-auth}/sso-providers/auth0.ts +0 -0
  25. /package/src/{app/api/auth → libs/next-auth}/sso-providers/authentik.ts +0 -0
  26. /package/src/{app/api/auth → libs/next-auth}/sso-providers/azure-ad.ts +0 -0
  27. /package/src/{app/api/auth → libs/next-auth}/sso-providers/github.ts +0 -0
  28. /package/src/{app/api/auth → libs/next-auth}/sso-providers/index.ts +0 -0
  29. /package/src/{app/api/auth → libs/next-auth}/sso-providers/zitadel.ts +0 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 0.147.16](https://github.com/lobehub/lobe-chat/compare/v0.147.15...v0.147.16)
6
+
7
+ <sup>Released on **2024-04-14**</sup>
8
+
9
+ #### ♻ Code Refactoring
10
+
11
+ - **misc**: Refactor the auth.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### Code refactoring
19
+
20
+ - **misc**: Refactor the auth, closes [#2043](https://github.com/lobehub/lobe-chat/issues/2043) ([37ecb41](https://github.com/lobehub/lobe-chat/commit/37ecb41))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
5
30
  ### [Version 0.147.15](https://github.com/lobehub/lobe-chat/compare/v0.147.14...v0.147.15)
6
31
 
7
32
  <sup>Released on **2024-04-14**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.147.15",
3
+ "version": "0.147.16",
4
4
  "description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
5
5
  "keywords": [
6
6
  "framework",
@@ -1,3 +1,3 @@
1
- export { GET, POST } from '../next-auth';
1
+ export { GET, POST } from '@/libs/next-auth';
2
2
 
3
3
  export const runtime = 'edge'; // optional
@@ -56,7 +56,11 @@ const useStyles = createStyles(({ css, prefixCls, token }) => {
56
56
 
57
57
  const isMac = isMacOS();
58
58
 
59
- const Footer = memo<{ setExpand?: (expand: boolean) => void }>(({ setExpand }) => {
59
+ interface FooterProps {
60
+ setExpand?: (expand: boolean) => void;
61
+ }
62
+
63
+ const Footer = memo<FooterProps>(({ setExpand }) => {
60
64
  const { t } = useTranslation('chat');
61
65
 
62
66
  const { theme, styles } = useStyles();
@@ -193,4 +197,6 @@ const Footer = memo<{ setExpand?: (expand: boolean) => void }>(({ setExpand }) =
193
197
  );
194
198
  });
195
199
 
200
+ Footer.displayName = 'Footer';
201
+
196
202
  export default Footer;
@@ -31,7 +31,11 @@ const useStyles = createStyles(({ css }) => {
31
31
  };
32
32
  });
33
33
 
34
- const InputArea = memo<{ setExpand?: (expand: boolean) => void }>(({ setExpand }) => {
34
+ interface InputAreaProps {
35
+ setExpand?: (expand: boolean) => void;
36
+ }
37
+
38
+ const InputArea = memo<InputAreaProps>(({ setExpand }) => {
35
39
  const { t } = useTranslation('chat');
36
40
  const { styles } = useStyles();
37
41
  const ref = useRef<TextAreaRef>(null);
@@ -119,4 +123,6 @@ const InputArea = memo<{ setExpand?: (expand: boolean) => void }>(({ setExpand }
119
123
  );
120
124
  });
121
125
 
126
+ InputArea.displayName = 'InputArea';
127
+
122
128
  export default InputArea;
@@ -7,8 +7,8 @@ import { isRtlLang } from 'rtl-detect';
7
7
  import Analytics from '@/components/Analytics';
8
8
  import { DEFAULT_LANG, LOBE_LOCALE_COOKIE } from '@/const/locale';
9
9
  import AuthProvider from '@/layout/AuthProvider';
10
- import GlobalLayout from '@/layout/GlobalLayout';
11
10
  import GlobalProvider from '@/layout/GlobalProvider';
11
+ import LayoutRoutes from '@/layout/routes';
12
12
  import { isMobileDevice } from '@/utils/responsive';
13
13
 
14
14
  const RootLayout = async ({ children }: PropsWithChildren) => {
@@ -22,7 +22,7 @@ const RootLayout = async ({ children }: PropsWithChildren) => {
22
22
  <body>
23
23
  <GlobalProvider>
24
24
  <AuthProvider>
25
- <GlobalLayout>{children}</GlobalLayout>
25
+ <LayoutRoutes>{children}</LayoutRoutes>
26
26
  </AuthProvider>
27
27
  </GlobalProvider>
28
28
  <Analytics />
@@ -57,24 +57,6 @@ export const getAppConfig = () => {
57
57
 
58
58
  PLUGIN_SETTINGS: process.env.PLUGIN_SETTINGS,
59
59
 
60
- ENABLE_OAUTH_SSO: !!process.env.ENABLE_OAUTH_SSO,
61
- SSO_PROVIDERS: process.env.SSO_PROVIDERS || 'auth0',
62
- AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID || '',
63
- AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET || '',
64
- AUTH0_ISSUER: process.env.AUTH0_ISSUER || '',
65
- GITHUB_CLIENT_ID: process.env.GITHUB_CLIENT_ID || '',
66
- GITHUB_CLIENT_SECRET: process.env.GITHUB_CLIENT_SECRET || '',
67
- AZURE_AD_CLIENT_ID: process.env.AZURE_AD_CLIENT_ID || '',
68
- AZURE_AD_CLIENT_SECRET: process.env.AZURE_AD_CLIENT_SECRET || '',
69
- AZURE_AD_TENANT_ID: process.env.AZURE_AD_TENANT_ID || '',
70
- AUTHENTIK_CLIENT_ID: process.env.AUTHENTIK_CLIENT_ID || '',
71
- AUTHENTIK_CLIENT_SECRET: process.env.AUTHENTIK_CLIENT_SECRET || '',
72
- AUTHENTIK_ISSUER: process.env.AUTHENTIK_ISSUER || '',
73
- ZITADEL_CLIENT_ID: process.env.ZITADEL_CLIENT_ID || '',
74
- ZITADEL_CLIENT_SECRET: process.env.ZITADEL_CLIENT_SECRET || '',
75
- ZITADEL_ISSUER: process.env.ZITADEL_ISSUER || '',
76
- NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET || '',
77
-
78
60
  ENABLE_LANGFUSE: process.env.ENABLE_LANGFUSE === '1',
79
61
  LANGFUSE_SECRET_KEY: process.env.LANGFUSE_SECRET_KEY || '',
80
62
  LANGFUSE_PUBLIC_KEY: process.env.LANGFUSE_PUBLIC_KEY || '',
@@ -0,0 +1,71 @@
1
+ /* eslint-disable sort-keys-fix/sort-keys-fix , typescript-sort-keys/interface */
2
+
3
+ declare global {
4
+ // eslint-disable-next-line @typescript-eslint/no-namespace
5
+ namespace NodeJS {
6
+ interface ProcessEnv {
7
+ ENABLE_OAUTH_SSO?: string;
8
+ SSO_PROVIDERS?: string;
9
+
10
+ AUTH0_CLIENT_ID?: string;
11
+ AUTH0_CLIENT_SECRET?: string;
12
+ AUTH0_ISSUER?: string;
13
+
14
+ // Github
15
+ GITHUB_CLIENT_ID?: string;
16
+ GITHUB_CLIENT_SECRET?: string;
17
+
18
+ // Azure AD
19
+ AZURE_AD_CLIENT_ID?: string;
20
+ AZURE_AD_CLIENT_SECRET?: string;
21
+ AZURE_AD_TENANT_ID?: string;
22
+
23
+ // AUTHENTIK
24
+ AUTHENTIK_CLIENT_ID?: string;
25
+ AUTHENTIK_CLIENT_SECRET?: string;
26
+ AUTHENTIK_ISSUER?: string;
27
+
28
+ // ZITADEL
29
+ ZITADEL_CLIENT_ID?: string;
30
+ ZITADEL_CLIENT_SECRET?: string;
31
+ ZITADEL_ISSUER?: string;
32
+ NEXTAUTH_SECRET?: string;
33
+ }
34
+ }
35
+ }
36
+
37
+ export const getAuthConfig = () => {
38
+ if (typeof process === 'undefined') {
39
+ throw new Error('[Server Config] you are importing a server-only module outside of server');
40
+ }
41
+
42
+ return {
43
+ ENABLE_OAUTH_SSO: !!process.env.ENABLE_OAUTH_SSO,
44
+ SSO_PROVIDERS: process.env.SSO_PROVIDERS || 'auth0',
45
+
46
+ // Auth0
47
+ AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID || '',
48
+ AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET || '',
49
+ AUTH0_ISSUER: process.env.AUTH0_ISSUER || '',
50
+
51
+ // Github
52
+ GITHUB_CLIENT_ID: process.env.GITHUB_CLIENT_ID || '',
53
+ GITHUB_CLIENT_SECRET: process.env.GITHUB_CLIENT_SECRET || '',
54
+
55
+ // Azure AD
56
+ AZURE_AD_CLIENT_ID: process.env.AZURE_AD_CLIENT_ID || '',
57
+ AZURE_AD_CLIENT_SECRET: process.env.AZURE_AD_CLIENT_SECRET || '',
58
+ AZURE_AD_TENANT_ID: process.env.AZURE_AD_TENANT_ID || '',
59
+
60
+ // AUTHENTIK
61
+ AUTHENTIK_CLIENT_ID: process.env.AUTHENTIK_CLIENT_ID || '',
62
+ AUTHENTIK_CLIENT_SECRET: process.env.AUTHENTIK_CLIENT_SECRET || '',
63
+ AUTHENTIK_ISSUER: process.env.AUTHENTIK_ISSUER || '',
64
+
65
+ // ZITADEL
66
+ ZITADEL_CLIENT_ID: process.env.ZITADEL_CLIENT_ID || '',
67
+ ZITADEL_CLIENT_SECRET: process.env.ZITADEL_CLIENT_SECRET || '',
68
+ ZITADEL_ISSUER: process.env.ZITADEL_ISSUER || '',
69
+ NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET || '',
70
+ };
71
+ };
@@ -1,5 +1,6 @@
1
1
  import { getAnalyticsConfig } from './analytics';
2
2
  import { getAppConfig } from './app';
3
+ import { getAuthConfig } from './auth';
3
4
  import { getProviderConfig } from './provider';
4
5
 
5
6
  export const getServerConfig = () => {
@@ -9,7 +10,8 @@ export const getServerConfig = () => {
9
10
 
10
11
  const provider = getProviderConfig();
11
12
  const app = getAppConfig();
13
+ const auth = getAuthConfig();
12
14
  const analytics = getAnalyticsConfig();
13
15
 
14
- return { ...provider, ...app, ...analytics };
16
+ return { ...provider, ...app, ...analytics, ...auth };
15
17
  };
@@ -0,0 +1,10 @@
1
+ import { SessionProvider } from 'next-auth/react';
2
+ import { PropsWithChildren } from 'react';
3
+
4
+ import { API_ENDPOINTS } from '@/services/_url';
5
+
6
+ const NextAuth = ({ children }: PropsWithChildren) => {
7
+ return <SessionProvider basePath={API_ENDPOINTS.oauth}>{children}</SessionProvider>;
8
+ };
9
+
10
+ export default NextAuth;
@@ -1,16 +1,12 @@
1
- import { SessionProvider } from 'next-auth/react';
2
1
  import { PropsWithChildren } from 'react';
3
2
 
4
3
  import { getServerConfig } from '@/config/server';
5
- import { API_ENDPOINTS } from '@/services/_url';
4
+
5
+ import NextAuth from './NextAuth';
6
6
 
7
7
  const { ENABLE_OAUTH_SSO = false } = getServerConfig();
8
8
 
9
9
  const AuthProvider = ({ children }: PropsWithChildren) =>
10
- ENABLE_OAUTH_SSO ? (
11
- <SessionProvider basePath={API_ENDPOINTS.oauth}>{children}</SessionProvider>
12
- ) : (
13
- children
14
- );
10
+ ENABLE_OAUTH_SSO ? <NextAuth>{children}</NextAuth> : children;
15
11
 
16
12
  export default AuthProvider;
@@ -0,0 +1,11 @@
1
+ import { memo } from 'react';
2
+
3
+ import AvatarWithUpload from '@/features/AvatarWithUpload';
4
+
5
+ const Avatar = memo(() => {
6
+ return <AvatarWithUpload id={'avatar'} />;
7
+ });
8
+
9
+ Avatar.displayName = 'Avatar';
10
+
11
+ export default Avatar;
@@ -1,9 +1,9 @@
1
1
  import { SideNav } from '@lobehub/ui';
2
2
  import { memo } from 'react';
3
3
 
4
- import AvatarWithUpload from '@/features/AvatarWithUpload';
5
4
  import { SidebarTabKey } from '@/store/global/initialState';
6
5
 
6
+ import Avatar from './Avatar';
7
7
  import BottomActions from './BottomActions';
8
8
  import TopActions from './TopActions';
9
9
 
@@ -14,7 +14,7 @@ interface Props {
14
14
  export default memo<Props>(({ sidebarKey }) => {
15
15
  return (
16
16
  <SideNav
17
- avatar={<AvatarWithUpload id={'avatar'} />}
17
+ avatar={<Avatar />}
18
18
  bottomActions={<BottomActions tab={sidebarKey} />}
19
19
  style={{ height: '100%' }}
20
20
  topActions={<TopActions tab={sidebarKey} />}
@@ -1,3 +1,5 @@
1
+ 'use client';
2
+
1
3
  import { type MobileNavBarTitleProps } from '@lobehub/ui';
2
4
  import { createStyles } from 'antd-style';
3
5
  import dynamic from 'next/dynamic';
@@ -0,0 +1,2 @@
1
+ export { default as DefaultLayoutDesktop } from './Desktop';
2
+ export { default as DefaultLayoutMobile } from './Mobile';
@@ -3,14 +3,16 @@
3
3
  import { usePathname } from 'next/navigation';
4
4
  import { PropsWithChildren, memo } from 'react';
5
5
 
6
- import Client from './Client';
6
+ import { DefaultLayoutDesktop } from '@/layout/DefaultLayout';
7
+
8
+ const defaultLayoutRoutes = new Set(['/']);
7
9
 
8
10
  const DesktopLayout = memo<PropsWithChildren>(({ children }) => {
9
11
  const pathname = usePathname();
10
12
 
11
- if (pathname === '/') return children;
13
+ if (defaultLayoutRoutes.has(pathname)) return children;
12
14
 
13
- return <Client>{children}</Client>;
15
+ return <DefaultLayoutDesktop>{children}</DefaultLayoutDesktop>;
14
16
  });
15
17
 
16
18
  export default DesktopLayout;
@@ -5,8 +5,7 @@ import { PropsWithChildren, memo } from 'react';
5
5
 
6
6
  import { useActiveTabKey } from '@/hooks/useActiveTabKey';
7
7
  import { useIsSubSlug } from '@/hooks/useIsSubSlug';
8
-
9
- import Layout from './Client';
8
+ import { DefaultLayoutMobile } from '@/layout/DefaultLayout';
10
9
 
11
10
  const MobileLayout = memo<PropsWithChildren>(({ children }) => {
12
11
  const pathname = usePathname();
@@ -16,9 +15,9 @@ const MobileLayout = memo<PropsWithChildren>(({ children }) => {
16
15
  if (pathname === '/') return children;
17
16
 
18
17
  return (
19
- <Layout showTabBar={!isSubPath} tabBarKey={tabBarKey}>
18
+ <DefaultLayoutMobile showTabBar={!isSubPath} tabBarKey={tabBarKey}>
20
19
  {children}
21
- </Layout>
20
+ </DefaultLayoutMobile>
22
21
  );
23
22
  });
24
23
 
@@ -3,6 +3,6 @@ import ServerLayout from '@/components/server/ServerLayout';
3
3
  import Desktop from './Desktop';
4
4
  import Mobile from './Mobile';
5
5
 
6
- const GlobalLayout = ServerLayout({ Desktop, Mobile });
6
+ const LayoutRoutes = ServerLayout({ Desktop, Mobile });
7
7
 
8
- export default GlobalLayout;
8
+ export default LayoutRoutes;
@@ -32,7 +32,7 @@ const nextAuth = NextAuth({
32
32
  async session({ session, token }) {
33
33
  // Pick userid from token
34
34
  if (session.user) {
35
- session.user.id = token.userId ?? session.user.id;
35
+ session.user.id = (token.userId ?? session.user.id) as string;
36
36
  }
37
37
  return session;
38
38
  },
package/src/middleware.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { NextResponse } from 'next/server';
2
2
 
3
3
  import { getServerConfig } from '@/config/server';
4
+ import { auth } from '@/libs/next-auth';
4
5
 
5
- import { auth } from './app/api/auth/next-auth';
6
6
  import { OAUTH_AUTHORIZED } from './const/auth';
7
7
 
8
8
  export const config = {