fix: avoid terminal cold-start paywall race

This commit is contained in:
2569718930@qq.com
2026-05-30 14:48:09 +08:00
parent 1c250906ed
commit c79619898a
4 changed files with 58 additions and 2 deletions
@@ -41,6 +41,12 @@ function firstKnownProfile(cookieResult: SettledProfile, bearerResult: SettledPr
};
}
function canResolveProfileImmediately(
payload: TerminalAuthProfilePayload | null,
): payload is TerminalAuthProfilePayload {
return payload?.authenticated === true && payload.subscription_active === true;
}
export async function loadTerminalAuthProfile({
getSession,
hasSupabasePublicEnv,
@@ -56,7 +62,7 @@ export async function loadTerminalAuthProfile({
});
const resolveIfAuthenticated = (payload: TerminalAuthProfilePayload | null) => {
if (!payload?.authenticated || resolvedAuthenticated) return;
if (!canResolveProfileImmediately(payload) || resolvedAuthenticated) return;
resolvedAuthenticated = true;
resolveAuthenticated?.(payload);
};