Files
zeekayandGitHub ea43c5a975 Type lib, scripts, v2, home and app under strict (#8)
* Type scripts under strict

Playwright's API the checks use is declared in host.ts (the package is
the app repo's); caught errors read through why(). tabs-tree.test waits
for the typed tabsTree.

Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk

* Type the shared components under strict

Window globals (__lenis, __hzHold, google) and the two react-dom calls
are declared in components/*.d.ts, since @types/react-dom is not a
dependency and the lockfile is frozen.

Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk

* Type components/v2 under strict

Props, state, refs and DOM events in the 93 v2 files. A2Motion's easing
tuples are as const. Two real bugs: x-archimedes/MaskLines imported a
NoJs that does not exist, and x-hypatia/PinChapters returned the element
from a ref callback, which React 19 reads as a cleanup. AppSheet no
longer sets aria-label to a JSX label.

Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk

* Type components/home under strict

The race, cost and frontier figures, the plan cards, the repository card
and the product stories take Run, Models and Plan types from lib.

Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk

* Type the hero devices and the app routes under strict

HeroScene and its parts describe hero-scenes.json; the [slug] pages take
params as a Promise, and metadata and viewport carry Next's types.

Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk

* Give the integrations previews their Preview type

Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk

* Use the bench Card type for the closing cards

Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk
2026-11-14 01:34:34 -08:00

83 lines
3.5 KiB
TypeScript

'use client';
/* Google One Tap for a visitor on hanzo.ai (hanzo-inc/app components/auth/tap.ts: the same client, the same rules).
Google offers the accounts this browser is signed in to Google as; a tap hands this page a signed credential, which
it neither reads nor trusts. The credential and the nonce Google bound it to go to this origin's sessionStorage
(`TAP`), never into an address, and the visitor goes to hanzo.ai's sign-in page. There hanzo.app starts its own
authorize request, and the app's panel finishes it with the credential as IAM's id_token_hint (`carried`), so IAM
verifies it and the session is hanzo.app's, its PKCE verifier never having left it.
Offered only on hanzo.ai (the origin the Google client allows), only where the visitor's consent lets a third
party be told which site is open (readConsent().marketing: nothing under GPC or Do Not Track, nothing in the EU
until accepted, and nothing until cloud's policy says which rule applies), never to a browser driven by a script,
and never to a visitor in Google's cooldown after dismissing it: prompt() keeps that. The sign-in pages are the
app's, which offer their own. */
import { useEffect } from 'react';
import { CONSENT_EVENT, POLICY_EVENT, readConsent } from '@hanzo/event';
import { SIGNIN } from '../lib/app';
/** IAM's provider-google client. Public: it is in the authorize address IAM sends a browser to. */
export const CLIENT = '113591532635-s8pvqrebprkbndluhftddmdap4htvu1p.apps.googleusercontent.com';
const SCRIPT = 'https://accounts.google.com/gsi/client';
/** Where the tap waits for the sign-in page (hanzo-inc/app components/auth/tap.ts `carried`). */
export const TAP = 'hanzo:tap';
/** Where a tap signs in: hanzo.ai's sign-in page, landing on Chat at hanzo.app/. */
const ENTRY = `${SIGNIN}/login`;
const offered = () =>
(location.hostname === 'hanzo.ai' || location.hostname === 'www.hanzo.ai') && navigator.webdriver !== true && readConsent().marketing;
/** Hands a tap to the sign-in page: kept for it in this tab, then the page. */
export function hand(credential: string | undefined, nonce: string) {
if (!credential) return;
try {
sessionStorage.setItem(TAP, JSON.stringify({ credential, nonce, at: Date.now() }));
} catch {
return;
}
location.assign(ENTRY);
}
export default function OneTap() {
useEffect(() => {
let asked = false;
const prompt = (id: GoogleIdentity) => {
const nonce = crypto.randomUUID();
id.initialize({
client_id: CLIENT,
nonce,
callback: ({ credential }: GoogleCredential) => hand(credential, nonce),
auto_select: false,
cancel_on_tap_outside: true,
use_fedcm_for_prompt: true,
itp_support: true,
context: 'signin',
});
id.prompt();
};
const ask = () => {
if (asked || !offered()) return;
asked = true;
if (window.google?.accounts?.id) return prompt(window.google.accounts.id);
const s = document.createElement('script');
s.src = SCRIPT;
s.async = true;
s.onload = () => window.google?.accounts?.id && prompt(window.google.accounts.id);
s.onerror = () => {
asked = false;
s.remove();
};
document.head.appendChild(s);
};
ask();
addEventListener(POLICY_EVENT, ask);
addEventListener(CONSENT_EVENT, ask);
return () => {
removeEventListener(POLICY_EVENT, ask);
removeEventListener(CONSENT_EVENT, ask);
window.google?.accounts?.id?.cancel();
};
}, []);
return null;
}