Skip to content
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

Merged
merged 24 commits into from May 14, 2024

Conversation

cy948
Copy link
Contributor

@cy948 cy948 commented May 4, 2024

💻 变更类型 | Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 🔨 chore
  • ⚡️ perf
  • 📝 docs

🔀 变更说明 | 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

Copy link

vercel bot commented May 4, 2024

@cy948 is attempting to deploy a commit to the LobeHub Team on Vercel.

A member of the Team first needs to authorize it.

@lobehubbot
Copy link
Member

👍 @cy948

Thank you for raising your pull request and contributing to our Community
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.
非常感谢您提出拉取请求并为我们的社区做出贡献,请确保您已经遵循了我们的贡献指南,我们会尽快审查它。
如果您遇到任何问题,请随时与我们联系。

Copy link

codecov bot commented May 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.21%. Comparing base (54524ab) to head (4006a59).
Report is 4 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

@@ -41,6 +42,11 @@ export const createAuthSlice: StateCreator<
login: async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

login 方法移除吧,都换到 openLogin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已移除

src/store/user/slices/auth/action.ts Show resolved Hide resolved
src/store/user/slices/auth/action.ts Show resolved Hide resolved
src/config/auth.ts Outdated Show resolved Hide resolved
docs/self-hosting/advanced/authentication.zh-CN.mdx Outdated Show resolved Hide resolved
@arvinxx
Copy link
Contributor

arvinxx commented May 6, 2024

另外需要补充下单测~

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


In addition, you need to place an additional order for testing~

@@ -76,6 +72,7 @@ export const createAuthSlice: StateCreator<

if (enableNextAuth) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉这一个判断可以移除了?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

既然 next-auth 没有 profile,那是否应该在左上角的model里隐藏“账户管理”呢?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的 要隐藏

@cy948
Copy link
Contributor Author

cy948 commented May 6, 2024

另外需要补充下单测~

已在 0eaf64b 补充

Copy link

vercel bot commented May 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lobe-chat-community ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 14, 2024 4:11am

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@cy948 After reading from serverConfigStore, do I still need the NEXT_PUBLIC variable?

@cy948
Copy link
Contributor Author

cy948 commented May 10, 2024

@cy948 换成从 serverConfigStore 读了以后,还需要 NEXT_PUBLIC 变量吗?

src/store/user/slices/auth/action.ts 这块还在用这个变量,也需要换成从 serverConfigStore 读吗?

@arvinxx
Copy link
Contributor

arvinxx commented May 10, 2024

src/store/user/slices/auth/action.ts 这块还在用这个变量,也需要换成从 serverConfigStore 读吗?

感觉如果可以的话,换成 serverConfigStore 读更好,这样 docker 估计就不会有 BreakingChange 了。

可以在 auth Slice 里加个方法:

 get enabledNextAuth: ()=>{ 
   return  serverConfigSelectors.enableOAuth(userServerConfigStore.getState())
}

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


src/store/user/slices/auth/action.ts is still using this variable. Does it need to be read from serverConfigStore instead?

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:

 get enabledNextAuth: ()=>{
   return serverConfigSelectors.enableOAuth(userServerConfigStore.getState())
}

@cy948
Copy link
Contributor Author

cy948 commented May 10, 2024

src/store/user/slices/auth/action.ts 这块还在用这个变量,也需要换成从 serverConfigStore 读吗?

感觉如果可以的话,换成 serverConfigStore 读更好,这样 docker 估计就不会有 BreakingChange 了。

可以在 auth Slice 里加个方法:

 get enabledNextAuth: ()=>{ 
   return  serverConfigSelectors.enableOAuth(userServerConfigStore.getState())
}

serverConfigSelectors 里有个 enabledOAuthSSO 可以进行判断,好像不需要新加方法

@cy948
Copy link
Contributor Author

cy948 commented May 10, 2024

@arvinxx这个Commit中。我把前台的 enableAuth, enableNextAuth 的判断都从 serverConfigStore 里读。后台保持不变,仍然从环境变量读。

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@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.

@@ -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.',
Copy link
Contributor

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 了吧?

Copy link
Contributor Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是不是有问题?userStore 里没有 serverConfig 的吧?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
应该是下面这一块里包含的,IDE有提示,实测也能正常控制开关:

export type UserStore = SyncAction &
  UserState &
  SettingsAction &
  PreferenceAction &
  UserAuthAction &
  CommonAction;

@arvinxx
Copy link
Contributor

arvinxx commented May 13, 2024

@cy948 同步下 main,之前说的 profile 隐藏的逻辑已经实现好了,store里那部分代码可以删了

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@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.

@arvinxx arvinxx merged commit 6dbcd70 into lobehub:main May 14, 2024
6 checks passed
@lobehubbot
Copy link
Member

❤️ 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.
项目的成长离不开用户反馈和贡献,感谢您的贡献! 如果您对 LobeHub 开发者社区感兴趣,请加入我们的 discord,然后私信 @arvinxx@canisminor1990。他们会邀请您加入我们的私密开发者频道。我们将会讨论关于 Lobe Chat 的开发,分享和讨论全球范围内的 AI 消息。

github-actions bot pushed a commit that referenced this pull request May 14, 2024
### [Version&nbsp;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>
@lobehubbot
Copy link
Member

🎉 This PR is included in version 0.159.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions bot pushed a commit to bentwnghk/lobe-chat that referenced this pull request May 14, 2024
## [Version&nbsp;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>
TheNameIsNigel pushed a commit to TheNameIsNigel/lobe-chat that referenced this pull request May 15, 2024
* ♻️ 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
TheNameIsNigel pushed a commit to TheNameIsNigel/lobe-chat that referenced this pull request May 15, 2024
### [Version&nbsp;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>
akvsdk pushed a commit to akvsdk/lobe-chat that referenced this pull request May 20, 2024
* ♻️ 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
akvsdk pushed a commit to akvsdk/lobe-chat that referenced this pull request May 20, 2024
### [Version&nbsp;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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] 通用设置里的访问密码及登录按钮消失
3 participants