@lobehub/chat 0.124.3 → 0.125.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 (86) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +8 -8
  3. package/README.zh-CN.md +8 -8
  4. package/docs/Deployment/Authentication.md +72 -0
  5. package/docs/Deployment/Authentication.zh-CN.md +72 -0
  6. package/docs/Deployment/Environment-Variable.md +50 -0
  7. package/docs/Deployment/Environment-Variable.zh-CN.md +50 -0
  8. package/docs/Development/Authentication.md +85 -0
  9. package/docs/Development/Authentication.zh-CN.md +83 -0
  10. package/locales/ar/common.json +1 -0
  11. package/locales/ar/error.json +6 -0
  12. package/locales/ar/setting.json +16 -0
  13. package/locales/de-DE/common.json +1 -0
  14. package/locales/de-DE/error.json +6 -0
  15. package/locales/de-DE/setting.json +16 -0
  16. package/locales/en-US/common.json +1 -0
  17. package/locales/en-US/error.json +6 -0
  18. package/locales/en-US/setting.json +16 -0
  19. package/locales/es-ES/common.json +1 -0
  20. package/locales/es-ES/error.json +6 -0
  21. package/locales/es-ES/setting.json +16 -0
  22. package/locales/fr-FR/common.json +1 -0
  23. package/locales/fr-FR/error.json +6 -0
  24. package/locales/fr-FR/setting.json +16 -0
  25. package/locales/it-IT/common.json +1 -0
  26. package/locales/it-IT/error.json +6 -0
  27. package/locales/it-IT/setting.json +16 -0
  28. package/locales/ja-JP/common.json +1 -0
  29. package/locales/ja-JP/error.json +6 -0
  30. package/locales/ja-JP/setting.json +16 -0
  31. package/locales/ko-KR/common.json +1 -0
  32. package/locales/ko-KR/error.json +6 -0
  33. package/locales/ko-KR/setting.json +16 -0
  34. package/locales/nl-NL/common.json +1 -0
  35. package/locales/nl-NL/error.json +6 -0
  36. package/locales/nl-NL/setting.json +16 -0
  37. package/locales/pl-PL/common.json +1 -0
  38. package/locales/pl-PL/error.json +6 -0
  39. package/locales/pl-PL/setting.json +16 -0
  40. package/locales/pt-BR/common.json +1 -0
  41. package/locales/pt-BR/error.json +6 -0
  42. package/locales/pt-BR/setting.json +16 -0
  43. package/locales/ru-RU/common.json +1 -0
  44. package/locales/ru-RU/error.json +6 -0
  45. package/locales/ru-RU/setting.json +16 -0
  46. package/locales/tr-TR/common.json +1 -0
  47. package/locales/tr-TR/error.json +6 -0
  48. package/locales/tr-TR/setting.json +16 -0
  49. package/locales/vi-VN/common.json +1 -0
  50. package/locales/vi-VN/error.json +6 -0
  51. package/locales/vi-VN/setting.json +16 -0
  52. package/locales/zh-CN/common.json +1 -0
  53. package/locales/zh-CN/error.json +6 -0
  54. package/locales/zh-CN/setting.json +16 -0
  55. package/locales/zh-TW/common.json +1 -0
  56. package/locales/zh-TW/error.json +6 -0
  57. package/locales/zh-TW/setting.json +16 -0
  58. package/package.json +2 -1
  59. package/src/app/api/auth.ts +7 -1
  60. package/src/app/api/chat/[provider]/route.ts +5 -3
  61. package/src/app/api/chat/auth.ts +11 -3
  62. package/src/app/api/chat/google/route.ts +5 -3
  63. package/src/app/api/config/route.ts +9 -2
  64. package/src/app/api/oauth/[...nextauth]/route.ts +3 -0
  65. package/src/app/api/oauth/next-auth.ts +21 -0
  66. package/src/app/api/openai/createBizOpenAI/index.ts +3 -2
  67. package/src/app/api/plugin/gateway/route.ts +7 -4
  68. package/src/app/settings/common/Common.tsx +39 -1
  69. package/src/app/settings/common/page.tsx +2 -2
  70. package/src/app/settings/page.tsx +2 -2
  71. package/src/chains/summaryTitle.ts +1 -1
  72. package/src/config/server/app.ts +5 -0
  73. package/src/const/auth.ts +2 -0
  74. package/src/const/fetch.ts +5 -1
  75. package/src/features/ChatInput/ActionBar/Clear.tsx +6 -8
  76. package/src/features/Conversation/Error/InvalidAccessCode.tsx +28 -10
  77. package/src/features/Conversation/Error/OAuthForm.tsx +95 -0
  78. package/src/layout/GlobalLayout/index.tsx +10 -7
  79. package/src/locales/default/common.ts +1 -0
  80. package/src/locales/default/error.ts +6 -0
  81. package/src/locales/default/setting.ts +16 -0
  82. package/src/middleware.ts +25 -0
  83. package/src/store/global/slices/common/initialState.ts +0 -1
  84. package/src/store/global/slices/common/selectors.ts +1 -0
  85. package/src/types/settings/index.ts +1 -0
  86. package/tsconfig.json +8 -8
@@ -0,0 +1,25 @@
1
+ // export { auth as middleware } from './app/api/next-auth';
2
+ import { NextResponse } from 'next/server';
3
+
4
+ import { auth } from './app/api/oauth/next-auth';
5
+ import { OAUTH_AUTHORIZED } from './const/auth';
6
+
7
+ export const config = {
8
+ matcher: '/api/:path*',
9
+ };
10
+
11
+ export default auth((req) => {
12
+ // Just check if session exists
13
+ const session = req.auth;
14
+ const isLoggedIn = !!session;
15
+
16
+ // Remove & amend OAuth authorized header
17
+ const requestHeaders = new Headers(req.headers);
18
+ requestHeaders.delete(OAUTH_AUTHORIZED);
19
+ if (isLoggedIn) requestHeaders.set(OAUTH_AUTHORIZED, 'true');
20
+ return NextResponse.next({
21
+ request: {
22
+ headers: requestHeaders,
23
+ },
24
+ });
25
+ });
@@ -1,6 +1,5 @@
1
1
  import { AppRouterInstance } from 'next/dist/shared/lib/app-router-context.shared-runtime';
2
2
 
3
-
4
3
  export enum SidebarTabKey {
5
4
  Chat = 'chat',
6
5
  Market = 'market',
@@ -1,5 +1,6 @@
1
1
  import { GlobalStore } from '@/store/global';
2
2
 
3
3
  export const commonSelectors = {
4
+ enabledOAuthSSO: (s: GlobalStore) => s.serverConfig.enabledOAuthSSO,
4
5
  userAvatar: (s: GlobalStore) => s.avatar || '',
5
6
  };
@@ -21,6 +21,7 @@ export interface GlobalTool {
21
21
  export interface GlobalServerConfig {
22
22
  customModelName?: string;
23
23
  defaultAgent?: DeepPartial<GlobalDefaultAgent>;
24
+ enabledOAuthSSO?: boolean;
24
25
  languageModel?: DeepPartial<GlobalLLMConfig>;
25
26
  }
26
27
 
package/tsconfig.json CHANGED
@@ -19,13 +19,13 @@
19
19
  "types": ["vitest/globals"],
20
20
  "paths": {
21
21
  "@/*": ["./src/*"],
22
- "~test-utils": ["./tests/utils.tsx"],
22
+ "~test-utils": ["./tests/utils.tsx"]
23
23
  },
24
24
  "plugins": [
25
25
  {
26
- "name": "next",
27
- },
28
- ],
26
+ "name": "next"
27
+ }
28
+ ]
29
29
  },
30
30
  "exclude": ["node_modules"],
31
31
  "include": [
@@ -36,11 +36,11 @@
36
36
  "**/*.ts",
37
37
  "**/*.d.ts",
38
38
  "**/*.tsx",
39
- ".next/types/**/*.ts",
39
+ ".next/types/**/*.ts"
40
40
  ],
41
41
  "ts-node": {
42
42
  "compilerOptions": {
43
- "module": "commonjs",
44
- },
45
- },
43
+ "module": "commonjs"
44
+ }
45
+ }
46
46
  }