|
|
|
@ -7,6 +7,11 @@ import { |
|
|
|
isAuthenticatedToken, |
|
|
|
MARRIAGE_ENTRY_PATH_COOKIE, |
|
|
|
} from "@/lib/entry-route-cache"; |
|
|
|
import { |
|
|
|
getSubmitPath, |
|
|
|
hasCompletedMarriageProfileBasics, |
|
|
|
} from "@/lib/get-submit-path"; |
|
|
|
import { fetchProfileSSR } from "@/lib/ssr-fetch"; |
|
|
|
import { localizePath } from "@/translations/config"; |
|
|
|
|
|
|
|
export const dynamic = "force-dynamic"; |
|
|
|
@ -21,6 +26,13 @@ export default async function LocaleEntryPage({ |
|
|
|
cookieStore.get("HABIB_TOKEN")?.value ?? |
|
|
|
cookieStore.get("habib_token")?.value; |
|
|
|
const hasToken = isAuthenticatedToken(token); |
|
|
|
|
|
|
|
// 1. If not authenticated, render <Intro /> instantly in SSR
|
|
|
|
if (!hasToken) { |
|
|
|
return <Intro />; |
|
|
|
} |
|
|
|
|
|
|
|
// 2. Check cached entry path first
|
|
|
|
const cachedEntryPath = getAuthenticatedCachedEntryPath( |
|
|
|
token, |
|
|
|
cookieStore.get(MARRIAGE_ENTRY_PATH_COOKIE)?.value, |
|
|
|
@ -30,12 +42,16 @@ export default async function LocaleEntryPage({ |
|
|
|
redirect(localizePath(cachedEntryPath, lang)); |
|
|
|
} |
|
|
|
|
|
|
|
// 1. If not authenticated, render <Intro /> instantly in SSR (0ms client delay)
|
|
|
|
if (!hasToken) { |
|
|
|
return <Intro />; |
|
|
|
// 3. Deep SSR Profile Resolution: resolve profile & redirect directly on server
|
|
|
|
const profile = await fetchProfileSSR(token); |
|
|
|
if (profile) { |
|
|
|
const targetPath = hasCompletedMarriageProfileBasics(profile) |
|
|
|
? getSubmitPath(profile) |
|
|
|
: "/intro"; |
|
|
|
redirect(localizePath(targetPath, lang)); |
|
|
|
} |
|
|
|
|
|
|
|
// 2. If authenticated without cached route, deliver head/web_ready immediately and resolve in client
|
|
|
|
// 4. Graceful Fallback if server fetch was unreachable
|
|
|
|
return ( |
|
|
|
<> |
|
|
|
<EntryRouteResolver anonymousEntryVisible={false} /> |
|
|
|
|