From fe01f3ac72e728d0bc59a5943d8d236ae82d43c8 Mon Sep 17 00:00:00 2001 From: NFish Date: Fri, 11 Apr 2025 16:54:11 +0800 Subject: [PATCH] fix: webapp sign in support new webapp_auth config --- web/app/(shareLayout)/webapp-signin/page.tsx | 31 ++++++++++++++----- .../app/app-access-control/index.tsx | 2 +- .../specific-groups-or-members.tsx | 2 +- web/i18n/en-US/login.ts | 5 +++ web/i18n/ja-JP/login.ts | 5 +++ web/i18n/zh-Hans/login.ts | 5 +++ web/types/feature.ts | 4 +-- 7 files changed, 43 insertions(+), 11 deletions(-) diff --git a/web/app/(shareLayout)/webapp-signin/page.tsx b/web/app/(shareLayout)/webapp-signin/page.tsx index d54bbe4dd3..a485cb6caa 100644 --- a/web/app/(shareLayout)/webapp-signin/page.tsx +++ b/web/app/(shareLayout)/webapp-signin/page.tsx @@ -3,6 +3,7 @@ import { useRouter, useSearchParams } from 'next/navigation' import type { FC } from 'react' import React, { useCallback, useEffect } from 'react' import { useTranslation } from 'react-i18next' +import { RiDoorLockLine } from '@remixicon/react' import cn from '@/utils/classnames' import Toast from '@/app/components/base/toast' import { fetchWebOAuth2SSOUrl, fetchWebOIDCSSOUrl, fetchWebSAMLSSOUrl } from '@/service/share' @@ -98,18 +99,34 @@ const WebSSOForm: FC = () => { init() }, [message, processTokenAndRedirect, tokenFromUrl]) - if (systemFeatures.webapp_auth.enable) { - return ( -
-
- + if (systemFeatures.webapp_auth.enabled) { + if (systemFeatures.webapp_auth.allow_sso) { + return ( +
+
+ +
+ ) + } + return
+
+
+ +
+

{t('login.webapp.noLoginMethod')}

+

{t('login.webapp.noLoginMethodTip')}

- ) +
+ +
+
} else { return
-

Current App is not required for login, you can click here continue.

+

{t('login.webapp.disabled')}

} } diff --git a/web/app/components/app/app-access-control/index.tsx b/web/app/components/app/app-access-control/index.tsx index 23a5386965..f5c12e2d85 100644 --- a/web/app/components/app/app-access-control/index.tsx +++ b/web/app/components/app/app-access-control/index.tsx @@ -35,7 +35,7 @@ export default function AccessControl(props: AccessControlProps) { useEffect(() => { setAppId(app.id) setCurrentMenu(app.access_mode ?? AccessMode.SPECIFIC_GROUPS_MEMBERS) - }, [app, setAppId]) + }, [app, setAppId, setCurrentMenu]) const { isPending, mutateAsync: updateAccessMode } = useUpdateAccessMode() const handleConfirm = useCallback(async () => { diff --git a/web/app/components/app/app-access-control/specific-groups-or-members.tsx b/web/app/components/app/app-access-control/specific-groups-or-members.tsx index 8d8e93b56a..a2e9cd52b6 100644 --- a/web/app/components/app/app-access-control/specific-groups-or-members.tsx +++ b/web/app/components/app/app-access-control/specific-groups-or-members.tsx @@ -20,7 +20,7 @@ export default function SpecificGroupsOrMembers() { const setSpecificMembers = useAccessControlStore(s => s.setSpecificMembers) const { t } = useTranslation() const systemFeatures = useGlobalPublicStore(s => s.systemFeatures) - const hideTip = systemFeatures.webapp_auth.enable + const hideTip = systemFeatures.webapp_auth.enabled const { isPending, data } = useAppWhiteListSubjects(appId, Boolean(appId) && currentMenu === AccessMode.SPECIFIC_GROUPS_MEMBERS) useEffect(() => { diff --git a/web/i18n/en-US/login.ts b/web/i18n/en-US/login.ts index 5ff7b80b4e..25fe8f9e75 100644 --- a/web/i18n/en-US/login.ts +++ b/web/i18n/en-US/login.ts @@ -104,6 +104,11 @@ const translation = { licenseLostTip: 'Failed to connect Dify license server. Please contact your administrator to continue using Dify.', licenseInactive: 'License Inactive', licenseInactiveTip: 'The Dify Enterprise license for your workspace is inactive. Please contact your administrator to continue using Dify.', + webapp: { + noLoginMethod: 'Authentication method not configured for webapp', + noLoginMethodTip: 'Please contact the system admin to add an authentication method.', + disabled: 'Webapp authentication is disabled. Please contact the system admin to enable it. You can try to use the app directly.', + }, } export default translation diff --git a/web/i18n/ja-JP/login.ts b/web/i18n/ja-JP/login.ts index 7ba8047aff..974212564f 100644 --- a/web/i18n/ja-JP/login.ts +++ b/web/i18n/ja-JP/login.ts @@ -105,6 +105,11 @@ const translation = { licenseInactiveTip: 'ワークスペースの Dify Enterprise ライセンスが非アクティブです。Difyを引き続き使用するには、管理者に連絡してください。', licenseExpired: 'ライセンスの有効期限が切れています', licenseLostTip: 'Difyライセンスサーバーへの接続に失敗しました。続けてDifyを使用するために管理者に連絡してください。', + webapp: { + noLoginMethod: 'Webアプリに対して認証方法が構成されていません', + noLoginMethodTip: 'システム管理者に連絡して、認証方法を追加してください。', + disabled: 'Webアプリの認証が無効になっています。システム管理者に連絡して有効にしてください。直接アプリを使用してみてください。', + }, } export default translation diff --git a/web/i18n/zh-Hans/login.ts b/web/i18n/zh-Hans/login.ts index 7f64c954b1..e2a958ea05 100644 --- a/web/i18n/zh-Hans/login.ts +++ b/web/i18n/zh-Hans/login.ts @@ -105,6 +105,11 @@ const translation = { licenseLostTip: '无法连接 Dify 许可证服务器,请联系管理员以继续使用 Dify。', licenseInactive: '许可证未激活', licenseInactiveTip: '您所在空间的 Dify Enterprise 许可证尚未激活,请联系管理员以继续使用 Dify。', + webapp: { + noLoginMethod: 'Web 应用未配置身份认证方式', + noLoginMethodTip: '请联系系统管理员添加身份认证方式', + disabled: 'Web 应用身份认证已禁用,请联系系统管理员启用。您也可以尝试直接使用应用。', + }, } export default translation diff --git a/web/types/feature.ts b/web/types/feature.ts index bdbd0a4d4b..3739fd2928 100644 --- a/web/types/feature.ts +++ b/web/types/feature.ts @@ -36,7 +36,7 @@ export type SystemFeatures = { application_title: string } webapp_auth: { - enable: boolean + enabled: boolean allow_sso: boolean sso_config: { protocol: SSOProtocol @@ -65,7 +65,7 @@ export const defaultSystemFeatures: SystemFeatures = { application_title: 'test title', }, webapp_auth: { - enable: false, + enabled: false, allow_sso: false, sso_config: { protocol: SSOProtocol.SAML,