Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | 1x 1x 52x 52x 52x 52x 52x 52x 52x 52x 52x 12x 52x 52x 52x 52x 3x 12x 12x | "use client";
import Link from "next/link";
import { useRouter, useSearchParams } from "next/navigation";
import { Suspense, useEffect } from "react";
import { ShieldCheck } from "lucide-react";
import { WalletFlow } from "@/components/wallet/PhoneFrame";
import { REGISTER_STEPS, LOGIN_STEPS } from "@/components/wallet/flows";
import { EudiApprovalFlow } from "@/components/wallet/EudiApprovalFlow";
import { WalletSignInStatus } from "@/components/wallet/WalletSignInStatus";
import { setDemoPersona } from "@/lib/use-demo-persona";
import { useWalletSignIn } from "@/lib/use-wallet-sign-in";
import { CITIZEN_WALLET } from "@/lib/wallet-config";
import { useT } from "@/lib/i18n/translate";
const WALLET = CITIZEN_WALLET;
function EudiQrContent() {
const t = useT("admin");
// Read at render-time (not module load) so it is deterministic in tests and
// immune to test-ordering env pollution; NEXT_PUBLIC_* is build-inlined anyway.
const IS_STATIC = process.env.NEXT_PUBLIC_STATIC_EXPORT === "true";
const searchParams = useSearchParams();
const router = useRouter();
const callbackUrl = searchParams.get("callbackUrl") || "/overview";
const mode = searchParams.get("mode") === "login" ? "login" : "register";
const flow = useWalletSignIn({ callbackUrl });
const { start } = flow.presentation;
useEffect(() => {
Eif (!IS_STATIC) void start();
}, [IS_STATIC, start]);
const title =
mode === "login"
? t("Sign in with {wallet}", { wallet: WALLET.name })
: t("Register with {wallet}", { wallet: WALLET.name });
// The wallet's one-line description and the footnote, translated.
const walletVars = {
description: t(WALLET.description),
alternatives: t(WALLET.alternatives),
wallet: WALLET.name,
};
// Static export / demo: no live verifier backend, so drive an interactive
// QR + wallet-approval simulation; on approval, sign in as the demo patient
// and forward to their personal health record (the "EHR page").
Iif (IS_STATIC) {
const onComplete = () => {
setDemoPersona("patient1");
try {
localStorage.setItem("demo-persona", "patient1");
} catch {
/* storage unavailable — non-fatal for the visual demo */
}
router.push(callbackUrl);
};
return (
<div className="min-h-[60vh] flex flex-col items-center justify-center gap-6 py-10 px-4">
<div className="text-center max-w-md">
<ShieldCheck
size={40}
className="mx-auto mb-2 text-blue-800 dark:text-blue-300"
/>
<h1 className="text-2xl font-bold text-(--text-primary) mb-1">
{title}
</h1>
<p className="text-(--text-secondary) text-sm">
{t(
"Scan the QR with {description}, {alternatives}, or approve on the simulated phone (OpenID4VP).",
walletVars,
)}
<br />
<span className="text-xs">
{t("Synthetic demo · signs you in as the demo patient")}
</span>
</p>
</div>
<EudiApprovalFlow
mode={mode}
onComplete={onComplete}
onCancel={() => router.push("/")}
/>
<Link
href="/auth/signin"
className="text-xs text-(--text-secondary) hover:text-(--accent) underline"
>
← {t("Back to other sign-in options")}
</Link>
</div>
);
}
return (
<div className="min-h-[60vh] flex flex-col items-center justify-center gap-6 py-10 px-4">
<div className="flex flex-col lg:flex-row items-center justify-center gap-6 w-full max-w-4xl">
<div className="bg-(--surface-2) rounded-lg p-8 max-w-md w-full text-center">
<ShieldCheck
size={44}
className="mx-auto mb-3 text-blue-800 dark:text-blue-300"
/>
<h1 className="text-2xl font-bold text-(--text-primary) mb-1">
{title}
</h1>
<p className="text-(--text-secondary) text-sm mb-6">
{t(
"Scan the QR code with {description}, {alternatives}, to prove who you are (OpenID4VP).",
walletVars,
)}
<br />
<span className="text-xs">
{t("Synthetic records · your PID opens the one in your name")}
</span>
</p>
<WalletSignInStatus flow={flow} />
</div>
<div className="flex flex-col items-center gap-2 shrink-0">
<WalletFlow
interactive
loop={false}
theme="dyou"
ariaLabel={
mode === "login"
? t("Simulated {wallet} login", walletVars)
: t("Simulated {wallet} register", walletVars)
}
steps={mode === "login" ? LOGIN_STEPS : REGISTER_STEPS}
onComplete={() => void flow.approveSimulated()}
onCancel={() => router.push("/auth/signin")}
/>
<p className="text-xs text-(--text-secondary) max-w-[280px] text-center">
{t(
"What happens on your phone. No {wallet} yet? Approve here to sign in as the demo patient.",
walletVars,
)}
</p>
{flow.demoHint && (
<p
role="status"
className="text-xs text-amber-600 dark:text-amber-400 max-w-[280px] text-center"
>
{t(flow.demoHint, walletVars)}
</p>
)}
</div>
</div>
<Link
href="/auth/signin"
className="text-xs text-(--text-secondary) hover:text-(--accent) underline"
>
← {t("Back to other sign-in options")}
</Link>
</div>
);
}
export default function EudiQrPage() {
const tc = useT("common");
return (
<Suspense
fallback={
<div className="min-h-[60vh] flex items-center justify-center">
<div className="text-(--text-secondary)">{tc("Loading…")}</div>
</div>
}
>
<EudiQrContent />
</Suspense>
);
}
|