New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
♻️ refactor: Move next-auth hooks to user store actions #2364
Conversation
@cy948 is attempting to deploy a commit to the LobeHub Team on Vercel. A member of the Team first needs to authorize it. |
👍 @cy948 Thank you for raising your pull request and contributing to our Community |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2364 +/- ##
==========================================
+ Coverage 93.16% 93.21% +0.05%
==========================================
Files 321 321
Lines 19372 19377 +5
Branches 1451 2280 +829
==========================================
+ Hits 18047 18062 +15
+ Misses 1325 1315 -10 ☔ View full report in Codecov by Sentry. |
src/store/user/slices/auth/action.ts
Outdated
@@ -41,6 +42,11 @@ export const createAuthSlice: StateCreator< | |||
login: async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
login
方法移除吧,都换到 openLogin
里
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已移除
另外需要补充下单测~ |
In addition, you need to place an additional order for testing~ |
src/store/user/slices/auth/action.ts
Outdated
@@ -76,6 +72,7 @@ export const createAuthSlice: StateCreator< | |||
|
|||
if (enableNextAuth) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感觉这一个判断可以移除了?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
既然 next-auth 没有 profile,那是否应该在左上角的model里隐藏“账户管理”呢?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的 要隐藏
已在 0eaf64b 补充 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@cy948 After reading from serverConfigStore, do I still need the |
|
感觉如果可以的话,换成 serverConfigStore 读更好,这样 docker 估计就不会有 BreakingChange 了。 可以在 auth Slice 里加个方法:
|
I feel that if possible, it would be better to switch to serverConfigStore for reading, so that docker will probably not have BreakingChange. You can add a method to the store:
|
|
@arvinxx in this Commit. I read the front-end enableAuth and enableNextAuth judgments from serverConfigStore. The background remains unchanged and still reads from environment variables. |
src/config/auth.ts
Outdated
@@ -52,7 +53,7 @@ declare global { | |||
export const getAuthConfig = () => { | |||
if (process.env.ENABLE_OAUTH_SSO) { | |||
console.warn( | |||
'`ENABLE_OAUTH_SSO` is deprecated and will be removed in LobeChat 1.0. just set `NEXT_AUTH_SECRET` enough', | |||
'`ENABLE_OAUTH_SSO` is deprecated and will be removed in LobeChat 1.0. Please set `NEXT_PUBLIC_ENABLE_NEXT_AUTH` instead.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里也不需要 NEXT_PUBLIC_ENABLE_NEXT_AUTH 了吧?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
确实,我改一下。
return enableClerk || get()?.enabledNextAuth(); | ||
}, | ||
enabledNextAuth: () => { | ||
return !!get()?.serverConfig.enabledOAuthSSO; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是不是有问题?userStore 里没有 serverConfig 的吧?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cy948 同步下 main,之前说的 profile 隐藏的逻辑已经实现好了,store里那部分代码可以删了 |
@cy948 Synchronize the main. The logic hidden by the profile mentioned before has been implemented. That part of the code in the store can be deleted. |
❤️ Great PR @cy948 ❤️ The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world. |
### [Version 0.159.1](v0.159.0...v0.159.1) <sup>Released on **2024-05-14**</sup> #### ♻ Code Refactoring - **misc**: Move next-auth hooks to user store actions. #### 🐛 Bug Fixes - **misc**: Pin `antd@5.17.0` to fix build error. <br/> <details> <summary><kbd>Improvements and Fixes</kbd></summary> #### Code refactoring * **misc**: Move next-auth hooks to user store actions, closes [#2364](#2364) ([6dbcd70](6dbcd70)) #### What's fixed * **misc**: Pin `antd@5.17.0` to fix build error, closes [#2483](#2483) ([aa03833](aa03833)) </details> <div align="right"> [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top) </div>
🎉 This PR is included in version 0.159.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
## [Version 1.39.0](v1.38.1...v1.39.0) <sup>Released on **2024-05-14**</sup> #### ♻ Code Refactoring - **misc**: Move next-auth hooks to user store actions. #### ✨ Features - **misc**: Support DeepSeek as new model provider. #### 🐛 Bug Fixes - **misc**: Dragging text mistakenly as image, pin `antd@5.17.0` to fix build error. <br/> <details> <summary><kbd>Improvements and Fixes</kbd></summary> #### Code refactoring * **misc**: Move next-auth hooks to user store actions, closes [lobehub#2364](https://github.com/bentwnghk/lobe-chat/issues/2364) ([6dbcd70](6dbcd70)) #### What's improved * **misc**: Support DeepSeek as new model provider, closes [lobehub#2446](https://github.com/bentwnghk/lobe-chat/issues/2446) ([18028f3](18028f3)) #### What's fixed * **misc**: Dragging text mistakenly as image, closes [lobehub#2111](https://github.com/bentwnghk/lobe-chat/issues/2111) ([3c047ef](3c047ef)) * **misc**: Pin `antd@5.17.0` to fix build error, closes [lobehub#2483](https://github.com/bentwnghk/lobe-chat/issues/2483) ([aa03833](aa03833)) </details> <div align="right"> [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top) </div>
* ♻️ refactor: move next-auth hooks to store acitons * 🔥 refactor: remove redundant files * ♻️ refactor: add next-auth hooks * ♻️ refactor: add env `NEXT_PUBLIC_ENABLE_NEXT_AUTH` * 📝 docs: update docs for new NextAuth env * ♻️ refactor: remove `login` in auth actions * 🐛fix: login buttion not shown on settings * ✅ test: hooks in auth actions * ♻️ refactor: change button show condition * ♻️ refactor: use server config to show oauth button * 🐛fix: context error in settings * ♻️ refactor: use server config store to enable auth * 💬 refactor: remove tips * ♻️ refactor: remove env `NEXT_PUBLIC_ENABLE_NEXT_AUTH` * 🔥 refactor: remove open profile in store auth actions * ✅ test(useMenu): change states
### [Version 0.159.1](lobehub/lobe-chat@v0.159.0...v0.159.1) <sup>Released on **2024-05-14**</sup> #### ♻ Code Refactoring - **misc**: Move next-auth hooks to user store actions. #### 🐛 Bug Fixes - **misc**: Pin `antd@5.17.0` to fix build error. <br/> <details> <summary><kbd>Improvements and Fixes</kbd></summary> #### Code refactoring * **misc**: Move next-auth hooks to user store actions, closes [lobehub#2364](lobehub#2364) ([6dbcd70](lobehub@6dbcd70)) #### What's fixed * **misc**: Pin `antd@5.17.0` to fix build error, closes [lobehub#2483](lobehub#2483) ([aa03833](lobehub@aa03833)) </details> <div align="right"> [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top) </div>
* ♻️ refactor: move next-auth hooks to store acitons * 🔥 refactor: remove redundant files * ♻️ refactor: add next-auth hooks * ♻️ refactor: add env `NEXT_PUBLIC_ENABLE_NEXT_AUTH` * 📝 docs: update docs for new NextAuth env * ♻️ refactor: remove `login` in auth actions * 🐛fix: login buttion not shown on settings * ✅ test: hooks in auth actions * ♻️ refactor: change button show condition * ♻️ refactor: use server config to show oauth button * 🐛fix: context error in settings * ♻️ refactor: use server config store to enable auth * 💬 refactor: remove tips * ♻️ refactor: remove env `NEXT_PUBLIC_ENABLE_NEXT_AUTH` * 🔥 refactor: remove open profile in store auth actions * ✅ test(useMenu): change states
### [Version 0.159.1](lobehub/lobe-chat@v0.159.0...v0.159.1) <sup>Released on **2024-05-14**</sup> #### ♻ Code Refactoring - **misc**: Move next-auth hooks to user store actions. #### 🐛 Bug Fixes - **misc**: Pin `antd@5.17.0` to fix build error. <br/> <details> <summary><kbd>Improvements and Fixes</kbd></summary> #### Code refactoring * **misc**: Move next-auth hooks to user store actions, closes [lobehub#2364](lobehub#2364) ([6dbcd70](lobehub@6dbcd70)) #### What's fixed * **misc**: Pin `antd@5.17.0` to fix build error, closes [lobehub#2483](lobehub#2483) ([aa03833](lobehub@aa03833)) </details> <div align="right"> [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top) </div>
💻 变更类型 | Change Type
🔀 变更说明 | Description of Change
fix [Bug] 通用设置里的访问密码及登录按钮消失 #2391
✨
src/store/user/slices/auth/action.ts
: 增加next-auth
的登陆、登出 Hooks;♻️
src/features/Conversation/Error/OAuthForm.tsx
:改为使用 UserStore 的登陆方法和用户信息获取方法;♻️
src/app/(main)/settings/common/features/Common.tsx
:同上;🏷️
src/libs/next-auth/index.ts
:类型定义移动到 ->src/types/next-auth.d.ts
;🔥 删除
src/hooks/useOAuthSession.ts
📝
docs/self-hosting/advanced/authentication*
:补充新环境变量NEXT_PUBLIC_ENABLE_NEXT_AUTH
及变量NEXT_AUTH_SECRECT
变更;♻️
src/config/auth.ts
:补充新环境变量NEXT_PUBLIC_ENABLE_NEXT_AUTH
用于判断是否启用 next-auth🧪
src/store/user/slices/auth/action.test.ts
:补充对 next-auth hook 调用的测试;== 05/08/2024 更新 ==
src/app/(main)/settings/common/features/Common.tsx
: 使用serverConfigStore
的值决定是否隐藏ACCES_CODE
输入框 和 OAuth 登陆按钮;src/app/(main)/settings/common/index.tsx
:因上述原因,移除<Common />
的 props;== 05/12/2024 更新 ==
src/config/auth.ts
:去除环境变量NEXT_PUBLIC_ENABLE_NEXT_AUTH
及其提示== 05/13/2024 更新==
src/store/user/slices/auth/action.ts
:去除openUserProfile
中与 NextAuth 相关的内容📝 补充信息 | Additional Information
src/store/user/slices/auth/action.ts
:中依靠环境变量NEXT_PUBLIC_ENABLE_NEXTAUTH
判定是否使用 next-auth 登陆。对直接使用官方镜像的 next-auth 用户造成 breaking change。