Commit db8edc43 by Archer Committed by GitHub

Fix chat login (#6993)

* fix: chat home login

* doc
parent 5a221391
...@@ -10,6 +10,10 @@ description: 'FastGPT V4.15.0-beta3 更新说明' ...@@ -10,6 +10,10 @@ description: 'FastGPT V4.15.0-beta3 更新说明'
## ⚙️ 优化 ## ⚙️ 优化
1. Skill 模块相关弹窗样式。
2. Skill list 接口性能。
3. 工作流节点名称和介绍输入。
## 🐛 修复 ## 🐛 修复
1. TTS 语音播放适配最新 OpenAI SDK,避免报错。 1. TTS 语音播放适配最新 OpenAI SDK,避免报错。
...@@ -20,3 +24,4 @@ description: 'FastGPT V4.15.0-beta3 更新说明' ...@@ -20,3 +24,4 @@ description: 'FastGPT V4.15.0-beta3 更新说明'
2. 重写了对话框相关代码,进行模块化细分。 2. 重写了对话框相关代码,进行模块化细分。
3. 优化单测性能,全量从 10 分支将至 5 分钟。 3. 优化单测性能,全量从 10 分支将至 5 分钟。
4. 升级 ts6。 4. 升级 ts6。
5. GitHub action 增强安全性。
...@@ -281,7 +281,7 @@ ...@@ -281,7 +281,7 @@
"content/self-host/upgrading/4-15/41502.en.mdx": "2026-05-25T11:21:30+08:00", "content/self-host/upgrading/4-15/41502.en.mdx": "2026-05-25T11:21:30+08:00",
"content/self-host/upgrading/4-15/41502.mdx": "2026-05-25T11:21:30+08:00", "content/self-host/upgrading/4-15/41502.mdx": "2026-05-25T11:21:30+08:00",
"content/self-host/upgrading/4-15/41503.en.mdx": "2026-05-25T11:21:30+08:00", "content/self-host/upgrading/4-15/41503.en.mdx": "2026-05-25T11:21:30+08:00",
"content/self-host/upgrading/4-15/41503.mdx": "2026-05-26T13:09:31+08:00", "content/self-host/upgrading/4-15/41503.mdx": "2026-05-26T20:01:48+08:00",
"content/self-host/upgrading/outdated/40.en.mdx": "2026-04-26T21:08:47+08:00", "content/self-host/upgrading/outdated/40.en.mdx": "2026-04-26T21:08:47+08:00",
"content/self-host/upgrading/outdated/40.mdx": "2026-04-26T21:08:47+08:00", "content/self-host/upgrading/outdated/40.mdx": "2026-04-26T21:08:47+08:00",
"content/self-host/upgrading/outdated/41.en.mdx": "2026-04-26T21:08:47+08:00", "content/self-host/upgrading/outdated/41.en.mdx": "2026-04-26T21:08:47+08:00",
......
import React, { useCallback, useMemo } from 'react'; import React, { useCallback, useEffect, useMemo, useState } from 'react';
import NextHead from '@/components/common/NextHead'; import NextHead from '@/components/common/NextHead';
import { Box, Flex } from '@chakra-ui/react'; import { Box, Flex } from '@chakra-ui/react';
import { useChatStore } from '@/web/core/chat/context/useChatStore'; import { useChatStore } from '@/web/core/chat/context/useChatStore';
...@@ -89,6 +89,7 @@ const Chat = () => { ...@@ -89,6 +89,7 @@ const Chat = () => {
type ChatPageProps = { type ChatPageProps = {
appId: string; appId: string;
shouldInitUserInfo: boolean;
isStandalone?: string; isStandalone?: string;
showRunningStatus: boolean; showRunningStatus: boolean;
showSkillReferences: boolean; showSkillReferences: boolean;
...@@ -98,11 +99,22 @@ type ChatPageProps = { ...@@ -98,11 +99,22 @@ type ChatPageProps = {
showWholeResponse: boolean; showWholeResponse: boolean;
}; };
const ChatLogin = ({ onSuccess }: { onSuccess: (res: LoginSuccessResponseType) => void }) => {
const { feConfigs } = useSystemStore();
return (
<>
<NextHead title={feConfigs?.systemTitle}></NextHead>
<LoginModal onSuccess={onSuccess} />
</>
);
};
const ChatContent = (props: ChatPageProps) => { const ChatContent = (props: ChatPageProps) => {
const { appId: pageAppId, isStandalone } = props; const { appId: pageAppId, isStandalone } = props;
const { appId: storeAppId, chatId } = useChatStore(); const { appId: storeAppId, chatId } = useChatStore();
const { setUserInfo } = useUserStore(); const { setUserInfo } = useUserStore();
const { feConfigs } = useSystemStore();
const isInitedUser = useContextSelector(ChatPageContext, (v) => v.isInitedUser); const isInitedUser = useContextSelector(ChatPageContext, (v) => v.isInitedUser);
const userInfo = useContextSelector(ChatPageContext, (v) => v.userInfo); const userInfo = useContextSelector(ChatPageContext, (v) => v.userInfo);
...@@ -134,20 +146,14 @@ const ChatContent = (props: ChatPageProps) => { ...@@ -134,20 +146,14 @@ const ChatContent = (props: ChatPageProps) => {
if (!isInitedUser) { if (!isInitedUser) {
return ( return (
<PageContainer isLoading flex={'1'} p={4}> <PageContainer isLoading flex={'1'} p={4}>
<NextHead title={feConfigs?.systemTitle} icon={feConfigs?.favicon} /> <NextHead />
</PageContainer> </PageContainer>
); );
} }
// Not login // Not login
if (!userInfo) { if (!userInfo) {
return ( return <ChatLogin onSuccess={loginSuccess} />;
<>
<NextHead title={feConfigs?.systemTitle}></NextHead>
<LoginModal onSuccess={loginSuccess} />
</>
);
} }
// show main chat interface // show main chat interface
...@@ -171,6 +177,51 @@ const ChatContent = (props: ChatPageProps) => { ...@@ -171,6 +177,51 @@ const ChatContent = (props: ChatPageProps) => {
}; };
const Render = (props: ChatPageProps) => { const Render = (props: ChatPageProps) => {
const { feConfigs } = useSystemStore();
const { userInfo, setUserInfo, initUserInfo } = useUserStore();
const [isInitedUser, setIsInitedUser] = useState(!props.shouldInitUserInfo);
const loginSuccess = useCallback(
async (res: LoginSuccessResponseType) => {
setUserInfo(res.user);
},
[setUserInfo]
);
useEffect(() => {
if (!props.shouldInitUserInfo) return;
let isUnmounted = false;
const init = async () => {
try {
await initUserInfo();
} finally {
if (!isUnmounted) {
setIsInitedUser(true);
}
}
};
init();
return () => {
isUnmounted = true;
};
}, [initUserInfo, props.shouldInitUserInfo]);
if (!isInitedUser) {
return (
<PageContainer isLoading flex={'1'} p={4}>
<NextHead title={feConfigs?.systemTitle} icon={feConfigs?.favicon} />
</PageContainer>
);
}
if (!userInfo) {
return <ChatLogin onSuccess={loginSuccess} />;
}
return ( return (
<ChatPageContextProvider appId={props.appId}> <ChatPageContextProvider appId={props.appId}>
<ChatContent {...props} /> <ChatContent {...props} />
...@@ -182,6 +233,7 @@ export default Render; ...@@ -182,6 +233,7 @@ export default Render;
export async function getServerSideProps(context: any) { export async function getServerSideProps(context: any) {
const appId = context?.query?.appId || ''; const appId = context?.query?.appId || '';
const shouldInitUserInfo = !!context.req?.cookies?.fastgpt_token;
const chatQuoteReaderConfig = await (async () => { const chatQuoteReaderConfig = await (async () => {
try { try {
...@@ -205,13 +257,14 @@ export async function getServerSideProps(context: any) { ...@@ -205,13 +257,14 @@ export async function getServerSideProps(context: any) {
return { return {
props: { props: {
appId, appId,
shouldInitUserInfo,
showRunningStatus: chatQuoteReaderConfig?.showRunningStatus ?? true, showRunningStatus: chatQuoteReaderConfig?.showRunningStatus ?? true,
showSkillReferences: chatQuoteReaderConfig?.showSkillReferences ?? false, showSkillReferences: chatQuoteReaderConfig?.showSkillReferences ?? false,
showCite: chatQuoteReaderConfig?.showCite ?? true, showCite: chatQuoteReaderConfig?.showCite ?? true,
showFullText: chatQuoteReaderConfig?.showFullText ?? true, showFullText: chatQuoteReaderConfig?.showFullText ?? true,
canDownloadSource: chatQuoteReaderConfig?.canDownloadSource ?? true, canDownloadSource: chatQuoteReaderConfig?.canDownloadSource ?? true,
showWholeResponse: chatQuoteReaderConfig?.showWholeResponse ?? true, showWholeResponse: chatQuoteReaderConfig?.showWholeResponse ?? true,
...(await serviceSideProps(context, ['file', 'app', 'chat', 'workflow'])) ...(await serviceSideProps(context, ['file', 'app', 'chat', 'workflow', 'login', 'user']))
} }
}; };
} }
...@@ -67,20 +67,20 @@ export const ChatPageContextProvider = ({ ...@@ -67,20 +67,20 @@ export const ChatPageContextProvider = ({
const router = useRouter(); const router = useRouter();
const { feConfigs } = useSystemStore(); const { feConfigs } = useSystemStore();
const { setSource, setAppId, setLastPane, setLastChatAppId, lastPane } = useChatStore(); const { setSource, setAppId, setLastPane, setLastChatAppId, lastPane } = useChatStore();
const { userInfo, initUserInfo } = useUserStore(); const { userInfo } = useUserStore();
const { pane = lastPane || ChatSidebarPaneEnum.HOME } = router.query as { const { pane = lastPane || ChatSidebarPaneEnum.HOME } = router.query as {
pane: ChatSidebarPaneEnum; pane: ChatSidebarPaneEnum;
}; };
const [collapse, setCollapse] = useState<CollapseStatusType>(defaultCollapseStatus); const [collapse, setCollapse] = useState<CollapseStatusType>(defaultCollapseStatus);
const [isInitedUser, setIsInitedUser] = useState(false);
// Get recently used apps // Get recently used apps
const { data: myApps = [], refresh: refreshRecentlyUsed } = useRequest( const { data: myApps = [], refresh: refreshRecentlyUsed } = useRequest(
() => getRecentlyUsedApps(), () => getRecentlyUsedApps(),
{ {
manual: false, manual: false,
ready: !!userInfo,
errorToast: '', errorToast: '',
refreshDeps: [userInfo?.team?.tmbId], refreshDeps: [userInfo?.team?.tmbId],
pollingInterval: 30000, pollingInterval: 30000,
...@@ -88,17 +88,10 @@ export const ChatPageContextProvider = ({ ...@@ -88,17 +88,10 @@ export const ChatPageContextProvider = ({
} }
); );
// Initialize user info // Initialize chat page state
useMount(async () => { useMount(async () => {
if (routeAppId) setAppId(routeAppId); if (routeAppId) setAppId(routeAppId);
try {
await initUserInfo();
} catch (error) {
console.log('User not logged in:', error);
} finally {
setSource('online'); setSource('online');
setIsInitedUser(true);
}
}); });
// Sync appId to store as route/appId changes // Sync appId to store as route/appId changes
...@@ -115,7 +108,8 @@ export const ChatPageContextProvider = ({ ...@@ -115,7 +108,8 @@ export const ChatPageContextProvider = ({
}, },
{ {
manual: false, manual: false,
refreshDeps: [feConfigs.isPlus], ready: !!userInfo && !!feConfigs.isPlus,
refreshDeps: [feConfigs.isPlus, userInfo?.team?.tmbId],
onSuccess: (data) => { onSuccess: (data) => {
if (!data) return; if (!data) return;
...@@ -198,7 +192,7 @@ export const ChatPageContextProvider = ({ ...@@ -198,7 +192,7 @@ export const ChatPageContextProvider = ({
chatSettings, chatSettings,
refreshChatSetting, refreshChatSetting,
logos, logos,
isInitedUser, isInitedUser: true,
userInfo, userInfo,
myApps, myApps,
refreshRecentlyUsed refreshRecentlyUsed
...@@ -211,7 +205,6 @@ export const ChatPageContextProvider = ({ ...@@ -211,7 +205,6 @@ export const ChatPageContextProvider = ({
chatSettings, chatSettings,
refreshChatSetting, refreshChatSetting,
logos, logos,
isInitedUser,
userInfo, userInfo,
myApps, myApps,
refreshRecentlyUsed refreshRecentlyUsed
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment