test(auth): cover PSID external entry login

This commit is contained in:
2026-07-16 11:55:03 +08:00
parent e730799aa5
commit 0b96b5ed95
5 changed files with 87 additions and 1 deletions
@@ -44,6 +44,7 @@ export default function ExternalEntryPersist({
const authDispatch = useAuthDispatch();
const [hasPersisted, setHasPersisted] = useState(false);
const hasNavigatedRef = useRef(false);
const hasReinitializedForPsidRef = useRef(false);
const targetRoute = resolveExternalEntryTarget({ target });
const destination = resolveExternalEntryDestination({ target });
const resolvedPromotionType = resolveExternalEntryPromotionType({
@@ -94,6 +95,16 @@ export default function ExternalEntryPersist({
useEffect(() => {
if (hasNavigatedRef.current || !hasPersisted) return;
// AuthStatusChecker can initialize before this entry has persisted PSID.
// Re-run the check so PSID direct login is not skipped by that race.
if (hasValue(psid) && !hasReinitializedForPsidRef.current) {
if (!authState.hasInitialized || authState.isLoading) return;
hasReinitializedForPsidRef.current = true;
authDispatch({ type: "AuthInit" });
return;
}
if (!authState.hasInitialized || authState.isLoading) return;
hasNavigatedRef.current = true;
@@ -138,3 +149,7 @@ export default function ExternalEntryPersist({
</div>
);
}
function hasValue(value: string | null): value is string {
return typeof value === "string" && value.trim().length > 0;
}