fix: 修复未登录态授权刷新循环
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
2026-04-20 22:01:04 +08:00
parent 75944b1f1f
commit 39c7f0735f
5 changed files with 103 additions and 13 deletions

View File

@@ -186,6 +186,7 @@ export function PreGameSelectionFlow({
const authUi = useAuthUi();
const initialAgentUiStateRef = useRef(readCustomWorldAgentUiState());
const hasAppliedInitialAgentWorkspaceRef = useRef(false);
const hasRequestedInitialAgentWorkspaceAuthRef = useRef(false);
const [generatedCustomWorldProfile, setGeneratedCustomWorldProfile] =
useState<CustomWorldProfile | null>(null);
const [savedCustomWorldEntries, setSavedCustomWorldEntries] = useState<
@@ -340,16 +341,29 @@ export function PreGameSelectionFlow({
);
useEffect(() => {
if (hasAppliedInitialAgentWorkspaceRef.current) {
const initialAgentSessionId = initialAgentUiStateRef.current.activeSessionId;
if (!initialAgentSessionId || hasAppliedInitialAgentWorkspaceRef.current) {
return;
}
setPlatformTab('create');
// URL 或 sessionStorage 中残留的共创工作区属于受保护入口,
// 未登录时只允许先唤起登录弹窗,不能直接恢复会话请求。
if (!authUi?.user) {
if (!hasRequestedInitialAgentWorkspaceAuthRef.current) {
hasRequestedInitialAgentWorkspaceAuthRef.current = true;
authUi?.openLoginModal?.(() => {
setSelectionStage('agent-workspace');
});
}
return;
}
hasAppliedInitialAgentWorkspaceRef.current = true;
if (initialAgentUiStateRef.current.activeSessionId) {
setPlatformTab('create');
setSelectionStage('agent-workspace');
}
}, [setSelectionStage]);
setSelectionStage('agent-workspace');
}, [authUi?.openLoginModal, authUi?.user, setSelectionStage]);
useEffect(() => {
if (!selectedDetailEntry) {
@@ -530,6 +544,16 @@ export function PreGameSelectionFlow({
useEffect(() => {
if (!activeAgentSessionId) {
setAgentSession(null);
setAgentOperation(null);
setIsLoadingAgentSession(false);
setStreamingAgentReplyText('');
setIsStreamingAgentReply(false);
return;
}
if (!authUi?.user) {
setAgentSession(null);
setAgentOperation(null);
setIsLoadingAgentSession(false);
setStreamingAgentReplyText('');
setIsStreamingAgentReply(false);
@@ -572,13 +596,14 @@ export function PreGameSelectionFlow({
};
}, [
activeAgentSessionId,
authUi?.user,
persistAgentUiState,
setSelectionStage,
syncAgentSessionSnapshot,
]);
useEffect(() => {
if (!activeAgentSessionId || !activeAgentOperationId) {
if (!activeAgentSessionId || !activeAgentOperationId || !authUi?.user) {
return;
}
@@ -638,6 +663,7 @@ export function PreGameSelectionFlow({
}, [
activeAgentOperationId,
activeAgentSessionId,
authUi?.user,
persistAgentUiState,
syncAgentSessionSnapshot,
]);