From eddf4eeac6bc3adcc57869c243d6948e778a7438 Mon Sep 17 00:00:00 2001 From: NFish Date: Thu, 10 Apr 2025 10:50:49 +0800 Subject: [PATCH] feat: webapp supports login and logout --- web/app/(shareLayout)/webapp-signin/page.tsx | 21 ++-- .../chat/chat-with-history/sidebar/index.tsx | 14 ++- .../share/text-generation/index.tsx | 24 ++-- .../share/text-generation/info-modal.tsx | 49 ++++++++ .../share/text-generation/menu-dropdown.tsx | 107 ++++++++++++++++++ web/service/share.ts | 5 - 6 files changed, 189 insertions(+), 31 deletions(-) create mode 100644 web/app/components/share/text-generation/info-modal.tsx create mode 100644 web/app/components/share/text-generation/menu-dropdown.tsx diff --git a/web/app/(shareLayout)/webapp-signin/page.tsx b/web/app/(shareLayout)/webapp-signin/page.tsx index 12f4152c6f..f3ca649468 100644 --- a/web/app/(shareLayout)/webapp-signin/page.tsx +++ b/web/app/(shareLayout)/webapp-signin/page.tsx @@ -2,13 +2,17 @@ import { useRouter, useSearchParams } from 'next/navigation' import type { FC } from 'react' import React, { useEffect } from 'react' +import { useTranslation } from 'react-i18next' import cn from '@/utils/classnames' import Toast from '@/app/components/base/toast' -import { fetchSystemFeatures, fetchWebOAuth2SSOUrl, fetchWebOIDCSSOUrl, fetchWebSAMLSSOUrl } from '@/service/share' +import { fetchWebOAuth2SSOUrl, fetchWebOIDCSSOUrl, fetchWebSAMLSSOUrl } from '@/service/share' import { setAccessToken } from '@/app/components/share/utils' -import Loading from '@/app/components/base/loading' +import Button from '@/app/components/base/button' +import { useGlobalPublicStore } from '@/context/global-public-context' const WebSSOForm: FC = () => { + const { t } = useTranslation() + const systemFeatures = useGlobalPublicStore(s => s.systemFeatures) const searchParams = useSearchParams() const router = useRouter() @@ -42,14 +46,14 @@ const WebSSOForm: FC = () => { router.push(redirectUrl) } - const handleSSOLogin = async (protocol: string) => { + const handleSSOLogin = async () => { const appCode = getAppCodeFromRedirectUrl() if (!appCode || !redirectUrl) { showErrorToast('redirect url or app code is invalid.') return } - switch (protocol) { + switch (systemFeatures.sso_enforced_for_web_protocol) { case 'saml': { const samlRes = await fetchWebSAMLSSOUrl(appCode, redirectUrl) router.push(samlRes.url) @@ -72,18 +76,13 @@ const WebSSOForm: FC = () => { useEffect(() => { const init = async () => { - const res = await fetchSystemFeatures() - const protocol = res.sso_enforced_for_web_protocol - if (message) { showErrorToast(message) return } - if (!tokenFromUrl) { - await handleSSOLogin(protocol) + if (!tokenFromUrl) return - } await processTokenAndRedirect() } @@ -94,7 +93,7 @@ const WebSSOForm: FC = () => { return (
- +
) diff --git a/web/app/components/base/chat/chat-with-history/sidebar/index.tsx b/web/app/components/base/chat/chat-with-history/sidebar/index.tsx index 69716f9ed8..a4d0af3388 100644 --- a/web/app/components/base/chat/chat-with-history/sidebar/index.tsx +++ b/web/app/components/base/chat/chat-with-history/sidebar/index.tsx @@ -11,6 +11,7 @@ import { Edit05 } from '@/app/components/base/icons/src/vender/line/general' import type { ConversationItem } from '@/models/share' import Confirm from '@/app/components/base/confirm' import RenameModal from '@/app/components/base/chat/chat-with-history/sidebar/rename-modal' +import MenuDropdown from '@/app/components/share/text-generation/menu-dropdown' const Sidebar = () => { const { t } = useTranslation() @@ -115,11 +116,14 @@ const Sidebar = () => { ) } - {appData?.site.copyright && ( -
- © {(new Date()).getFullYear()} {appData?.site.copyright} -
- )} +
+ + {appData?.site.copyright && ( +
+ © {(new Date()).getFullYear()} {appData?.site.copyright} +
+ )} +
{!!showConfirm && ( = ({ 'shrink-0 relative flex flex-col pb-10 h-full border-r border-gray-100 bg-white', )}>
-
-
- -
{siteInfo.title}
+
+
+
+ +
{siteInfo.title}
+
+
{!isPC && (