@lobehub/chat 1.51.16 → 1.52.0

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/.env.example +1 -0
  2. package/CHANGELOG.md +25 -0
  3. package/Dockerfile.database +2 -1
  4. package/changelog/v1.json +9 -0
  5. package/next.config.ts +1 -0
  6. package/package.json +1 -1
  7. package/src/app/[variants]/(main)/(mobile)/me/(home)/__tests__/UserBanner.test.tsx +3 -2
  8. package/src/app/[variants]/(main)/(mobile)/me/(home)/__tests__/useCategory.test.tsx +5 -5
  9. package/src/app/[variants]/(main)/(mobile)/me/(home)/features/UserBanner.tsx +3 -6
  10. package/src/app/[variants]/(main)/(mobile)/me/(home)/features/useCategory.tsx +2 -2
  11. package/src/app/[variants]/(main)/(mobile)/me/profile/features/Category.tsx +2 -2
  12. package/src/app/[variants]/(main)/profile/(home)/Client.tsx +2 -2
  13. package/src/app/[variants]/(main)/profile/hooks/useCategory.tsx +2 -4
  14. package/src/app/[variants]/(main)/settings/_layout/Mobile/Header.tsx +1 -3
  15. package/src/app/[variants]/page.tsx +0 -1
  16. package/src/config/auth.ts +1 -2
  17. package/src/const/auth.ts +1 -2
  18. package/src/features/User/UserPanel/PanelContent.tsx +3 -7
  19. package/src/features/User/UserPanel/useMenu.tsx +2 -2
  20. package/src/features/User/__tests__/PanelContent.test.tsx +6 -7
  21. package/src/layout/GlobalProvider/StoreInitialization.tsx +1 -2
  22. package/src/middleware.ts +7 -10
  23. package/src/services/chat.ts +2 -1
  24. package/src/store/user/slices/auth/action.test.ts +4 -2
  25. package/src/store/user/slices/auth/action.ts +2 -4
  26. package/src/store/user/slices/auth/initialState.ts +0 -1
  27. package/src/store/user/slices/auth/selectors.ts +5 -7
  28. package/src/store/user/slices/common/action.ts +0 -1
  29. package/src/libs/agent-runtime/togetherai/__snapshots__/index.test.ts.snap +0 -2190
package/.env.example CHANGED
@@ -190,6 +190,7 @@ OPENAI_API_KEY=sk-xxxxxxxxx
190
190
 
191
191
 
192
192
  # NextAuth related configurations
193
+ # NEXT_PUBLIC_ENABLE_NEXT_AUTH=1
193
194
  # NEXT_AUTH_SECRET=
194
195
 
195
196
  # Auth0 configurations
package/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ## [Version 1.52.0](https://github.com/lobehub/lobe-chat/compare/v1.51.16...v1.52.0)
6
+
7
+ <sup>Released on **2025-02-08**</sup>
8
+
9
+ #### ✨ Features
10
+
11
+ - **misc**: Refactor the auth condition in Next Auth.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's improved
19
+
20
+ - **misc**: Refactor the auth condition in Next Auth, closes [#5866](https://github.com/lobehub/lobe-chat/issues/5866) ([e529108](https://github.com/lobehub/lobe-chat/commit/e529108))
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 1.51.16](https://github.com/lobehub/lobe-chat/compare/v1.51.15...v1.51.16)
6
31
 
7
32
  <sup>Released on **2025-02-07**</sup>
@@ -38,6 +38,7 @@ FROM base AS builder
38
38
  ARG USE_CN_MIRROR
39
39
  ARG NEXT_PUBLIC_BASE_PATH
40
40
  ARG NEXT_PUBLIC_SERVICE_MODE
41
+ ARG NEXT_PUBLIC_ENABLE_NEXT_AUTH
41
42
  ARG NEXT_PUBLIC_SENTRY_DSN
42
43
  ARG NEXT_PUBLIC_ANALYTICS_POSTHOG
43
44
  ARG NEXT_PUBLIC_POSTHOG_HOST
@@ -49,7 +50,7 @@ ARG NEXT_PUBLIC_UMAMI_WEBSITE_ID
49
50
  ENV NEXT_PUBLIC_BASE_PATH="${NEXT_PUBLIC_BASE_PATH}"
50
51
 
51
52
  ENV NEXT_PUBLIC_SERVICE_MODE="${NEXT_PUBLIC_SERVICE_MODE:-server}" \
52
- NEXT_PUBLIC_ENABLE_NEXT_AUTH="1" \
53
+ NEXT_PUBLIC_ENABLE_NEXT_AUTH="${NEXT_PUBLIC_ENABLE_NEXT_AUTH:-1}" \
53
54
  APP_URL="http://app.com" \
54
55
  DATABASE_DRIVER="node" \
55
56
  DATABASE_URL="postgres://postgres:password@localhost:5432/postgres" \
package/changelog/v1.json CHANGED
@@ -1,4 +1,13 @@
1
1
  [
2
+ {
3
+ "children": {
4
+ "features": [
5
+ "Refactor the auth condition in Next Auth."
6
+ ]
7
+ },
8
+ "date": "2025-02-08",
9
+ "version": "1.52.0"
10
+ },
2
11
  {
3
12
  "children": {},
4
13
  "date": "2025-02-07",
package/next.config.ts CHANGED
@@ -179,6 +179,7 @@ const nextConfig: NextConfig = {
179
179
  ],
180
180
  // when external packages in dev mode with turbopack, this config will lead to bundle error
181
181
  serverExternalPackages: isProd ? ['@electric-sql/pglite'] : undefined,
182
+
182
183
  transpilePackages: ['pdfjs-dist', 'mermaid'],
183
184
 
184
185
  webpack(config) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.51.16",
3
+ "version": "1.52.0",
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",
@@ -49,8 +49,9 @@ afterEach(() => {
49
49
  describe('UserBanner', () => {
50
50
  it('should render UserInfo and DataStatistics when auth is disabled', () => {
51
51
  act(() => {
52
- useUserStore.setState({ isSignedIn: false, enableAuth: () => false });
52
+ useUserStore.setState({ isSignedIn: false });
53
53
  });
54
+ enableAuth = false;
54
55
 
55
56
  render(<UserBanner />);
56
57
 
@@ -75,7 +76,7 @@ describe('UserBanner', () => {
75
76
 
76
77
  it('should render UserLoginOrSignup when user is not logged in with auth enabled', () => {
77
78
  act(() => {
78
- useUserStore.setState({ isSignedIn: false, enableAuth: () => true });
79
+ useUserStore.setState({ isSignedIn: false });
79
80
  });
80
81
  enableClerk = true;
81
82
 
@@ -45,12 +45,10 @@ afterEach(() => {
45
45
  enableClerk = true;
46
46
  });
47
47
 
48
- // 目前对 enableAuth 的判定是在 useUserStore 中,所以需要 mock useUserStore
49
- // 类型定义: enableAuth: () => boolean
50
48
  describe('useCategory', () => {
51
49
  it('should return correct items when the user is logged in with authentication', () => {
52
50
  act(() => {
53
- useUserStore.setState({ isSignedIn: true, enableAuth: () => true });
51
+ useUserStore.setState({ isSignedIn: true });
54
52
  });
55
53
  enableAuth = true;
56
54
  enableClerk = false;
@@ -70,8 +68,9 @@ describe('useCategory', () => {
70
68
 
71
69
  it('should return correct items when the user is not logged in', () => {
72
70
  act(() => {
73
- useUserStore.setState({ isSignedIn: false, enableAuth: () => true });
71
+ useUserStore.setState({ isSignedIn: false });
74
72
  });
73
+ enableAuth = true;
75
74
 
76
75
  const { result } = renderHook(() => useCategory(), { wrapper });
77
76
 
@@ -88,9 +87,10 @@ describe('useCategory', () => {
88
87
 
89
88
  it('should handle settings for non-authenticated users', () => {
90
89
  act(() => {
91
- useUserStore.setState({ isSignedIn: false, enableAuth: () => false });
90
+ useUserStore.setState({ isSignedIn: false });
92
91
  });
93
92
  enableClerk = false;
93
+ enableAuth = false;
94
94
 
95
95
  const { result } = renderHook(() => useCategory(), { wrapper });
96
96
 
@@ -5,6 +5,7 @@ import { useRouter } from 'next/navigation';
5
5
  import { memo } from 'react';
6
6
  import { Flexbox } from 'react-layout-kit';
7
7
 
8
+ import { enableAuth, enableNextAuth } from '@/const/auth';
8
9
  import { isDeprecatedEdition } from '@/const/version';
9
10
  import DataStatistics from '@/features/User/DataStatistics';
10
11
  import UserInfo from '@/features/User/UserInfo';
@@ -15,11 +16,7 @@ import { authSelectors } from '@/store/user/selectors';
15
16
  const UserBanner = memo(() => {
16
17
  const router = useRouter();
17
18
  const isLoginWithAuth = useUserStore(authSelectors.isLoginWithAuth);
18
- const [enableAuth, signIn, enabledNextAuth] = useUserStore((s) => [
19
- authSelectors.enabledAuth(s),
20
- s.openLogin,
21
- authSelectors.enabledNextAuth(s),
22
- ]);
19
+ const [signIn] = useUserStore((s) => [s.openLogin]);
23
20
 
24
21
  return (
25
22
  <Flexbox gap={12} paddingBlock={8}>
@@ -38,7 +35,7 @@ const UserBanner = memo(() => {
38
35
  <UserLoginOrSignup
39
36
  onClick={() => {
40
37
  // If use NextAuth, call openLogin method directly
41
- if (enabledNextAuth) {
38
+ if (enableNextAuth) {
42
39
  signIn();
43
40
  return;
44
41
  }
@@ -12,6 +12,7 @@ import { useRouter } from 'next/navigation';
12
12
  import { useTranslation } from 'react-i18next';
13
13
 
14
14
  import { CellProps } from '@/components/Cell';
15
+ import { enableAuth } from '@/const/auth';
15
16
  import { LOBE_CHAT_CLOUD } from '@/const/branding';
16
17
  import { DOCUMENTS, FEEDBACK, OFFICIAL_URL, UTM_SOURCE } from '@/const/url';
17
18
  import { isServerMode } from '@/const/version';
@@ -27,10 +28,9 @@ export const useCategory = () => {
27
28
  const { canInstall, install } = usePWAInstall();
28
29
  const { t } = useTranslation(['common', 'setting', 'auth']);
29
30
  const { showCloudPromotion, hideDocs } = useServerConfigStore(featureFlagsSelectors);
30
- const [isLogin, isLoginWithAuth, enableAuth] = useUserStore((s) => [
31
+ const [isLogin, isLoginWithAuth] = useUserStore((s) => [
31
32
  authSelectors.isLogin(s),
32
33
  authSelectors.isLoginWithAuth(s),
33
- authSelectors.enabledAuth(s),
34
34
  ]);
35
35
 
36
36
  const profile: CellProps[] = [
@@ -6,15 +6,15 @@ import { memo } from 'react';
6
6
  import { useTranslation } from 'react-i18next';
7
7
 
8
8
  import Cell, { CellProps } from '@/components/Cell';
9
+ import { enableAuth } from '@/const/auth';
9
10
  import { isDeprecatedEdition } from '@/const/version';
10
11
  import { ProfileTabs } from '@/store/global/initialState';
11
12
  import { useUserStore } from '@/store/user';
12
13
  import { authSelectors } from '@/store/user/selectors';
13
14
 
14
15
  const Category = memo(() => {
15
- const [isLogin, enableAuth, isLoginWithClerk, signOut] = useUserStore((s) => [
16
+ const [isLogin, isLoginWithClerk, signOut] = useUserStore((s) => [
16
17
  authSelectors.isLogin(s),
17
- authSelectors.enabledAuth(s),
18
18
  authSelectors.isLoginWithClerk(s),
19
19
  s.logout,
20
20
  ]);
@@ -4,6 +4,7 @@ import { Form, type ItemGroup } from '@lobehub/ui';
4
4
  import { memo } from 'react';
5
5
  import { useTranslation } from 'react-i18next';
6
6
 
7
+ import { enableAuth } from '@/const/auth';
7
8
  import { FORM_STYLE } from '@/const/layoutTokens';
8
9
  import AvatarWithUpload from '@/features/AvatarWithUpload';
9
10
  import UserAvatar from '@/features/User/UserAvatar';
@@ -14,8 +15,7 @@ type SettingItemGroup = ItemGroup;
14
15
 
15
16
  const Client = memo<{ mobile?: boolean }>(() => {
16
17
  const [isLoginWithNextAuth] = useUserStore((s) => [authSelectors.isLoginWithNextAuth(s)]);
17
- const [enableAuth, nickname, username, userProfile] = useUserStore((s) => [
18
- s.enableAuth(),
18
+ const [nickname, username, userProfile] = useUserStore((s) => [
19
19
  userProfileSelectors.nickName(s),
20
20
  userProfileSelectors.username(s),
21
21
  userProfileSelectors.userProfile(s),
@@ -4,6 +4,7 @@ import Link from 'next/link';
4
4
  import { useTranslation } from 'react-i18next';
5
5
 
6
6
  import type { MenuProps } from '@/components/Menu';
7
+ import { enableAuth } from '@/const/auth';
7
8
  import { isDeprecatedEdition } from '@/const/version';
8
9
  import { ProfileTabs } from '@/store/global/initialState';
9
10
  import { useUserStore } from '@/store/user';
@@ -11,10 +12,7 @@ import { authSelectors } from '@/store/user/slices/auth/selectors';
11
12
 
12
13
  export const useCategory = () => {
13
14
  const { t } = useTranslation('auth');
14
- const [enableAuth, isLoginWithClerk] = useUserStore((s) => [
15
- authSelectors.enabledAuth(s),
16
- authSelectors.isLoginWithClerk(s),
17
- ]);
15
+ const [isLoginWithClerk] = useUserStore((s) => [authSelectors.isLoginWithClerk(s)]);
18
16
 
19
17
  const cateItems: MenuProps['items'] = [
20
18
  {
@@ -6,13 +6,12 @@ import { memo } from 'react';
6
6
  import { useTranslation } from 'react-i18next';
7
7
  import { Flexbox } from 'react-layout-kit';
8
8
 
9
+ import { enableAuth } from '@/const/auth';
9
10
  import { useActiveSettingsKey } from '@/hooks/useActiveTabKey';
10
11
  import { useQueryRoute } from '@/hooks/useQueryRoute';
11
12
  import { useShowMobileWorkspace } from '@/hooks/useShowMobileWorkspace';
12
13
  import { SettingsTabs } from '@/store/global/initialState';
13
14
  import { useSessionStore } from '@/store/session';
14
- import { useUserStore } from '@/store/user';
15
- import { authSelectors } from '@/store/user/selectors';
16
15
  import { mobileHeaderSticky } from '@/styles/mobileHeader';
17
16
 
18
17
  const Header = memo(() => {
@@ -22,7 +21,6 @@ const Header = memo(() => {
22
21
  const showMobileWorkspace = useShowMobileWorkspace();
23
22
  const activeSettingsKey = useActiveSettingsKey();
24
23
  const isSessionActive = useSessionStore((s) => !!s.activeId);
25
- const enableAuth = useUserStore(authSelectors.enabledAuth);
26
24
 
27
25
  const handleBackClick = () => {
28
26
  if (isSessionActive && showMobileWorkspace) {
@@ -7,4 +7,3 @@ export const metadata: Metadata = {
7
7
  };
8
8
 
9
9
  export { default } from './loading';
10
-
@@ -217,8 +217,7 @@ export const getAuthConfig = () => {
217
217
  CLERK_WEBHOOK_SECRET: process.env.CLERK_WEBHOOK_SECRET,
218
218
 
219
219
  // Next Auth
220
- NEXT_PUBLIC_ENABLE_NEXT_AUTH:
221
- !!process.env.NEXT_AUTH_SECRET || process.env.NEXT_PUBLIC_ENABLE_NEXT_AUTH === '1',
220
+ NEXT_PUBLIC_ENABLE_NEXT_AUTH: process.env.NEXT_PUBLIC_ENABLE_NEXT_AUTH === '1',
222
221
  NEXT_AUTH_SSO_PROVIDERS: process.env.NEXT_AUTH_SSO_PROVIDERS,
223
222
  NEXT_AUTH_SECRET: process.env.NEXT_AUTH_SECRET,
224
223
  NEXT_AUTH_DEBUG: !!process.env.NEXT_AUTH_DEBUG,
package/src/const/auth.ts CHANGED
@@ -2,8 +2,7 @@ import { authEnv } from '@/config/auth';
2
2
 
3
3
  export const enableClerk = authEnv.NEXT_PUBLIC_ENABLE_CLERK_AUTH;
4
4
  export const enableNextAuth = authEnv.NEXT_PUBLIC_ENABLE_NEXT_AUTH;
5
- export const enableAuth =
6
- authEnv.NEXT_PUBLIC_ENABLE_CLERK_AUTH || authEnv.NEXT_PUBLIC_ENABLE_NEXT_AUTH;
5
+ export const enableAuth = enableClerk || enableNextAuth || false;
7
6
 
8
7
  export const LOBE_CHAT_AUTH_HEADER = 'X-lobe-chat-auth';
9
8
 
@@ -5,6 +5,7 @@ import { Flexbox } from 'react-layout-kit';
5
5
 
6
6
  import BrandWatermark from '@/components/BrandWatermark';
7
7
  import Menu from '@/components/Menu';
8
+ import { enableAuth, enableNextAuth } from '@/const/auth';
8
9
  import { isDeprecatedEdition } from '@/const/version';
9
10
  import { useUserStore } from '@/store/user';
10
11
  import { authSelectors } from '@/store/user/selectors';
@@ -19,12 +20,7 @@ import { useMenu } from './useMenu';
19
20
  const PanelContent = memo<{ closePopover: () => void }>(({ closePopover }) => {
20
21
  const router = useRouter();
21
22
  const isLoginWithAuth = useUserStore(authSelectors.isLoginWithAuth);
22
- const [openSignIn, signOut, enableAuth, enabledNextAuth] = useUserStore((s) => [
23
- s.openLogin,
24
- s.logout,
25
- s.enableAuth(),
26
- s.enabledNextAuth,
27
- ]);
23
+ const [openSignIn, signOut] = useUserStore((s) => [s.openLogin, s.logout]);
28
24
  const { mainItems, logoutItems } = useMenu();
29
25
 
30
26
  const handleSignIn = () => {
@@ -36,7 +32,7 @@ const PanelContent = memo<{ closePopover: () => void }>(({ closePopover }) => {
36
32
  signOut();
37
33
  closePopover();
38
34
  // NextAuth doesn't need to redirect to login page
39
- if (enabledNextAuth) return;
35
+ if (enableNextAuth) return;
40
36
  router.push('/login');
41
37
  };
42
38
 
@@ -21,6 +21,7 @@ import { useTranslation } from 'react-i18next';
21
21
  import { Flexbox } from 'react-layout-kit';
22
22
 
23
23
  import type { MenuProps } from '@/components/Menu';
24
+ import { enableAuth } from '@/const/auth';
24
25
  import { LOBE_CHAT_CLOUD } from '@/const/branding';
25
26
  import {
26
27
  DISCORD,
@@ -68,8 +69,7 @@ export const useMenu = () => {
68
69
  const hasNewVersion = useNewVersion();
69
70
  const { t } = useTranslation(['common', 'setting', 'auth']);
70
71
  const { showCloudPromotion, hideDocs } = useServerConfigStore(featureFlagsSelectors);
71
- const [enableAuth, isLogin, isLoginWithAuth] = useUserStore((s) => [
72
- authSelectors.enabledAuth(s),
72
+ const [isLogin, isLoginWithAuth] = useUserStore((s) => [
73
73
  authSelectors.isLogin(s),
74
74
  authSelectors.isLoginWithAuth(s),
75
75
  ]);
@@ -68,13 +68,12 @@ vi.mock('@/const/version', () => ({
68
68
  // 定义一个变量来存储 enableAuth 的值
69
69
  let enableAuth = true;
70
70
 
71
- beforeEach(() => {
72
- useUserStore.setState({ enableAuth: () => true });
73
- });
74
-
75
- afterEach(() => {
76
- enableAuth = true;
77
- });
71
+ // 模拟 @/const/auth 模块
72
+ vi.mock('@/const/auth', () => ({
73
+ get enableAuth() {
74
+ return enableAuth;
75
+ },
76
+ }));
78
77
 
79
78
  describe('PanelContent', () => {
80
79
  const closePopover = vi.fn();
@@ -5,6 +5,7 @@ import { memo } from 'react';
5
5
  import { useTranslation } from 'react-i18next';
6
6
  import { createStoreUpdater } from 'zustand-utils';
7
7
 
8
+ import { enableNextAuth } from '@/const/auth';
8
9
  import { useIsMobile } from '@/hooks/useIsMobile';
9
10
  import { useEnabledDataSync } from '@/hooks/useSyncData';
10
11
  import { useAgentStore } from '@/store/agent';
@@ -39,8 +40,6 @@ const StoreInitialization = memo(() => {
39
40
 
40
41
  // Update NextAuth status
41
42
  const useUserStoreUpdater = createStoreUpdater(useUserStore);
42
- const enableNextAuth = useServerConfigStore(serverConfigSelectors.enabledOAuthSSO);
43
- useUserStoreUpdater('enabledNextAuth', enableNextAuth);
44
43
  const oAuthSSOProviders = useServerConfigStore(serverConfigSelectors.oAuthSSOProviders);
45
44
  useUserStoreUpdater('oAuthSSOProviders', oAuthSSOProviders);
46
45
 
package/src/middleware.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server';
2
2
  import { NextRequest, NextResponse } from 'next/server';
3
3
  import { UAParser } from 'ua-parser-js';
4
- import urlJoin from 'url-join';
5
4
 
6
5
  import { authEnv } from '@/config/auth';
7
6
  import { LOBE_THEME_APPEARANCE } from '@/const/theme';
@@ -84,23 +83,21 @@ const defaultMiddleware = (request: NextRequest) => {
84
83
  if (['/api', '/trpc', '/webapi'].some((path) => url.pathname.startsWith(path)))
85
84
  return NextResponse.next();
86
85
 
87
- // 处理 URL 重写
88
- // 构建新路径: /${route}${originalPathname}
89
- // 只对 GET 请求进行 URL 重写,确保其他类型的请求(包括 OPTIONS)不受影响
90
- const nextPathname = `/${urlJoin(route, url.pathname)}`;
86
+ // refs: https://github.com/lobehub/lobe-chat/pull/5866
87
+ // new handle segment rewrite: /${route}${originalPathname}
88
+ // / -> /zh-CN__0__dark
89
+ // /discover -> /zh-CN__0__dark/discover
90
+ const nextPathname = `/${route}` + (url.pathname === '/' ? '' : url.pathname);
91
91
  console.log(`[rewrite] ${url.pathname} -> ${nextPathname}`);
92
+
92
93
  url.pathname = nextPathname;
93
94
 
94
- return NextResponse.rewrite(url);
95
+ return NextResponse.rewrite(url, { status: 200 });
95
96
  };
96
97
 
97
- const publicRoute = ['/', '/discover'];
98
-
99
98
  // Initialize an Edge compatible NextAuth middleware
100
99
  const nextAuthMiddleware = NextAuthEdge.auth((req) => {
101
100
  const response = defaultMiddleware(req);
102
- // skip the '/' route
103
- if (publicRoute.some((url) => req.nextUrl.pathname.startsWith(url))) return response;
104
101
 
105
102
  // Just check if session exists
106
103
  const session = req.auth;
@@ -3,6 +3,7 @@ import { produce } from 'immer';
3
3
  import { merge } from 'lodash-es';
4
4
 
5
5
  import { DEFAULT_MODEL_PROVIDER_LIST } from '@/config/modelProviders';
6
+ import { enableAuth } from '@/const/auth';
6
7
  import { INBOX_GUIDE_SYSTEMROLE } from '@/const/guide';
7
8
  import { INBOX_SESSION_ID } from '@/const/session';
8
9
  import { DEFAULT_AGENT_CONFIG } from '@/const/settings';
@@ -515,7 +516,7 @@ class ChatService {
515
516
  * if enable login and not signed in, return unauthorized error
516
517
  */
517
518
  const userStore = useUserStore.getState();
518
- if (userStore.enableAuth() && !userStore.isSignedIn) {
519
+ if (enableAuth && !userStore.isSignedIn) {
519
520
  throw AgentRuntimeError.createError(ChatErrorType.InvalidAccessCode);
520
521
  }
521
522
 
@@ -89,7 +89,7 @@ describe('createAuthSlice', () => {
89
89
  });
90
90
 
91
91
  it('should call next-auth signOut when NextAuth is enabled', async () => {
92
- useUserStore.setState({ enabledNextAuth: true });
92
+ enableNextAuth = true;
93
93
 
94
94
  const { result } = renderHook(() => useUserStore());
95
95
 
@@ -100,6 +100,7 @@ describe('createAuthSlice', () => {
100
100
  const { signOut } = await import('next-auth/react');
101
101
 
102
102
  expect(signOut).toHaveBeenCalled();
103
+ enableNextAuth = false;
103
104
  });
104
105
 
105
106
  it('should not call next-auth signOut when NextAuth is disabled', async () => {
@@ -143,7 +144,7 @@ describe('createAuthSlice', () => {
143
144
  });
144
145
 
145
146
  it('should call next-auth signIn when NextAuth is enabled', async () => {
146
- useUserStore.setState({ enabledNextAuth: true });
147
+ enableNextAuth = true;
147
148
 
148
149
  const { result } = renderHook(() => useUserStore());
149
150
 
@@ -154,6 +155,7 @@ describe('createAuthSlice', () => {
154
155
  const { signIn } = await import('next-auth/react');
155
156
 
156
157
  expect(signIn).toHaveBeenCalled();
158
+ enableNextAuth = false;
157
159
  });
158
160
  it('should not call next-auth signIn when NextAuth is disabled', async () => {
159
161
  const { result } = renderHook(() => useUserStore());
@@ -1,6 +1,6 @@
1
1
  import { StateCreator } from 'zustand/vanilla';
2
2
 
3
- import { enableClerk } from '@/const/auth';
3
+ import { enableAuth, enableClerk, enableNextAuth } from '@/const/auth';
4
4
 
5
5
  import { UserStore } from '../../store';
6
6
 
@@ -23,7 +23,7 @@ export const createAuthSlice: StateCreator<
23
23
  UserAuthAction
24
24
  > = (set, get) => ({
25
25
  enableAuth: () => {
26
- return enableClerk || get()?.enabledNextAuth || false;
26
+ return enableAuth;
27
27
  },
28
28
  logout: async () => {
29
29
  if (enableClerk) {
@@ -32,7 +32,6 @@ export const createAuthSlice: StateCreator<
32
32
  return;
33
33
  }
34
34
 
35
- const enableNextAuth = get().enabledNextAuth;
36
35
  if (enableNextAuth) {
37
36
  const { signOut } = await import('next-auth/react');
38
37
  signOut();
@@ -50,7 +49,6 @@ export const createAuthSlice: StateCreator<
50
49
  return;
51
50
  }
52
51
 
53
- const enableNextAuth = get().enabledNextAuth;
54
52
  if (enableNextAuth) {
55
53
  const { signIn } = await import('next-auth/react');
56
54
  // Check if only one provider is available
@@ -16,7 +16,6 @@ export interface UserAuthState {
16
16
  clerkSignIn?: (props?: SignInProps) => void;
17
17
  clerkSignOut?: SignOut;
18
18
  clerkUser?: UserResource;
19
- enabledNextAuth?: boolean;
20
19
  isLoaded?: boolean;
21
20
 
22
21
  isSignedIn?: boolean;
@@ -1,6 +1,6 @@
1
1
  import { t } from 'i18next';
2
2
 
3
- import { enableClerk } from '@/const/auth';
3
+ import { enableAuth, enableClerk, enableNextAuth } from '@/const/auth';
4
4
  import { BRANDING_NAME } from '@/const/branding';
5
5
  import { UserStore } from '@/store/user';
6
6
  import { LobeUser } from '@/types/user';
@@ -8,7 +8,7 @@ import { LobeUser } from '@/types/user';
8
8
  const DEFAULT_USERNAME = BRANDING_NAME;
9
9
 
10
10
  const nickName = (s: UserStore) => {
11
- if (!s.enableAuth()) return t('userPanel.defaultNickname', { ns: 'common' });
11
+ if (!enableAuth) return t('userPanel.defaultNickname', { ns: 'common' });
12
12
 
13
13
  if (s.isSignedIn) return s.user?.fullName || s.user?.username;
14
14
 
@@ -16,7 +16,7 @@ const nickName = (s: UserStore) => {
16
16
  };
17
17
 
18
18
  const username = (s: UserStore) => {
19
- if (!s.enableAuth()) return DEFAULT_USERNAME;
19
+ if (!enableAuth) return DEFAULT_USERNAME;
20
20
 
21
21
  if (s.isSignedIn) return s.user?.username;
22
22
 
@@ -36,17 +36,15 @@ export const userProfileSelectors = {
36
36
  */
37
37
  const isLogin = (s: UserStore) => {
38
38
  // 如果没有开启鉴权,说明不需要登录,默认是登录态
39
- if (!s.enableAuth()) return true;
39
+ if (!enableAuth) return true;
40
40
 
41
41
  return s.isSignedIn;
42
42
  };
43
43
 
44
44
  export const authSelectors = {
45
- enabledAuth: (s: UserStore): boolean => s.enableAuth(),
46
- enabledNextAuth: (s: UserStore): boolean => !!s.enabledNextAuth,
47
45
  isLoaded: (s: UserStore) => s.isLoaded,
48
46
  isLogin,
49
47
  isLoginWithAuth: (s: UserStore) => s.isSignedIn,
50
48
  isLoginWithClerk: (s: UserStore): boolean => (s.isSignedIn && enableClerk) || false,
51
- isLoginWithNextAuth: (s: UserStore): boolean => (s.isSignedIn && !!s.enabledNextAuth) || false,
49
+ isLoginWithNextAuth: (s: UserStore): boolean => (s.isSignedIn && !!enableNextAuth) || false,
52
50
  };
@@ -99,7 +99,6 @@ export const createCommonSlice: StateCreator<
99
99
  set(
100
100
  {
101
101
  defaultSettings,
102
- enabledNextAuth: serverConfig.enabledOAuthSSO,
103
102
  isOnboard: data.isOnboard,
104
103
  isShowPWAGuide: data.canEnablePWAGuide,
105
104
  isUserCanEnableTrace: data.canEnableTrace,