feat(navigation): add external entry routing

This commit is contained in:
2026-07-09 14:43:28 +08:00
parent 0659e52d29
commit 9159f5346d
17 changed files with 398 additions and 152 deletions
@@ -0,0 +1,79 @@
"use client";
import { useEffect } from "react";
import { useRouter } from "next/navigation";
import {
persistExternalEntryPayload,
resolveExternalEntryTarget,
} from "@/lib/navigation/external_entry";
import { Logger } from "@/utils";
const log = new Logger("ExternalEntryPersist");
interface ExternalEntryPersistProps {
deviceId: string | null;
facebookId: string | null;
facebookAppId: string | null;
avatarUrl: string | null;
target: string | null;
redirect: string | null;
next: string | null;
}
export default function ExternalEntryPersist({
deviceId,
facebookId,
facebookAppId,
avatarUrl,
target,
redirect,
next,
}: ExternalEntryPersistProps) {
const router = useRouter();
useEffect(() => {
const destination = resolveExternalEntryTarget({
target,
redirect,
next,
});
void (async () => {
try {
await persistExternalEntryPayload({
deviceId,
facebookId,
facebookAppId,
avatarUrl,
});
} catch (error) {
log.warn("[ExternalEntryPersist] failed to persist payload", error);
} finally {
router.replace(destination);
}
})();
}, [
avatarUrl,
deviceId,
facebookAppId,
facebookId,
next,
redirect,
router,
target,
]);
return (
<div
className="flex flex-1 items-center justify-center"
style={{ minHeight: "100dvh" }}
>
<div
aria-label="Redirecting"
className="size-10 animate-spin rounded-full border-4 border-t-transparent"
style={{ borderColor: "var(--color-accent)" }}
/>
</div>
);
}