mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 00:18:27 +00:00
feat(cli): the sign-in page the browser lands on follows the design (#7332)
* feat(cli): the sign-in page the browser lands on follows the design * style(cli): format the sign-in page files * fix(cli): the sign-in page picks Cancel or failure inside the page builder, and drops unused code
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
/** The page the browser lands on after sign-in: one design for the CLI's three endings. */
|
||||
|
||||
const MARK_A =
|
||||
"M10.1851 57.8021L33.1145 73.8313C36.2202 75.9978 41.5173 73.5433 42.4816 69.4984L51.7611 30.4271C52.7253 26.3822 48.5802 23.9277 44.4602 26.0942L13.917 42.1235C6.96677 45.7676 4.97564 54.1579 10.1851 57.8021Z";
|
||||
const MARK_B =
|
||||
"M87.5129 57.5141L56.9696 73.5433C52.8371 75.7098 48.7046 73.2553 49.6688 69.2104L58.9483 30.1391C59.9125 26.0942 65.2097 23.6397 68.3154 25.8062L91.2447 41.8354C96.4668 45.4796 94.4631 53.8699 87.5129 57.5141Z";
|
||||
|
||||
const STYLE = `:root{color-scheme:light dark;--bg:#f2f0ed;--ink:#1d1b18;--ink2:#5d5a55;--tile:#dff3ea;--tile-ink:#087a54;--bad:#fbe6e1;--bad-ink:#b3402e;--btn:#1d1b18;--btn-ink:#f2f0ed;--panel:#0c0c0e;--panel-ink:#f4f1ec}
|
||||
@media(prefers-color-scheme:dark){:root{--bg:#201e1b;--ink:#f6f4f1;--ink2:#b5b1aa;--tile:#1f3a2f;--tile-ink:#37de91;--bad:#3a2420;--bad-ink:#f08a78;--btn:#f6f4f1;--btn-ink:#201e1b}}
|
||||
*{box-sizing:border-box}html,body{height:100%;margin:0}
|
||||
body{background:var(--bg);color:var(--ink);font:400 15px/1.45 "TT Norms",system-ui,-apple-system,"Segoe UI",sans-serif;-webkit-font-smoothing:antialiased;display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1.25fr)}
|
||||
.col{position:relative;display:flex;flex-direction:column;justify-content:center;padding:48px 32px 48px max(32px,min(7vw,96px))}
|
||||
.brand{position:absolute;top:28px;left:32px;display:flex;align-items:center;gap:10px;font-weight:600;font-size:20px;letter-spacing:-.01em}
|
||||
.tile{display:grid;place-items:center;width:44px;height:44px;border-radius:12px;background:var(--tile);color:var(--tile-ink);margin-bottom:20px}
|
||||
.bad .tile{background:var(--bad);color:var(--bad-ink)}
|
||||
h1{margin:0;font-size:30px;line-height:1.1;font-weight:600;letter-spacing:-.02em;text-wrap:balance}
|
||||
p{margin:10px 0 0;color:var(--ink2);max-width:360px;text-wrap:pretty}
|
||||
code{font:500 13px ui-monospace,SFMono-Regular,Menlo,monospace;color:var(--ink2)}
|
||||
.panel{margin:14px;border-radius:24px;background:var(--panel);color:var(--panel-ink);display:flex;flex-direction:column;align-items:center;justify-content:center;gap:18px}
|
||||
.panel b{font-size:26px;font-weight:600;letter-spacing:-.01em}
|
||||
.panel small{color:rgb(244 241 236/.58);font-size:14px;margin-top:-10px}
|
||||
.badge{position:relative}
|
||||
.chk{display:none;position:absolute;right:-8px;bottom:-4px;width:22px;height:22px;border-radius:50%;background:#37de91;place-items:center}
|
||||
.ok .chk{display:grid}
|
||||
@media(max-width:760px){body{grid-template-columns:1fr;grid-template-rows:auto auto}.col{padding:84px 24px 32px}.brand{left:24px}.panel{min-height:300px;margin:12px}}`;
|
||||
|
||||
const CHECK =
|
||||
'<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="m5.5 12.5 4.2 4.2 8.8-9.4"/></svg>';
|
||||
const CROSS =
|
||||
'<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"><path d="M6.5 6.5l11 11M17.5 6.5l-11 11"/></svg>';
|
||||
|
||||
const CHK =
|
||||
'<span class="chk"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#0e1a14" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"><path d="m6 12.5 4 4 8-9"/></svg></span>';
|
||||
|
||||
function mark(width: number, height: number, id: string): string {
|
||||
const gradient = (suffix: string, x1: string, y1: string, x2: string, y2: string): string =>
|
||||
`<linearGradient id="${suffix}${id}" gradientUnits="userSpaceOnUse" x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}"><stop offset="0" stop-color="#06E3FA"/><stop offset="1" stop-color="#4FDB5E"/></linearGradient>`;
|
||||
return `<svg viewBox="4 22 92 56" width="${width}" height="${height}" aria-hidden="true"><defs>${gradient("a", "48.57", "25", "44.78", "71.94")}${gradient("b", "54.83", "73.84", "72.1", "32.89")}</defs><path fill="url(#a${id})" d="${MARK_A}"/><path fill="url(#b${id})" d="${MARK_B}"/></svg>`;
|
||||
}
|
||||
|
||||
function escapeHtml(s: string): string {
|
||||
return s
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
function page(args: { ok: boolean; title: string; text: string; detail?: string }): string {
|
||||
const detail = args.detail ? `<p><code>${escapeHtml(args.detail)}</code></p>` : "";
|
||||
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${escapeHtml(args.title)}</title><style>${STYLE}</style></head><body class="${args.ok ? "ok" : "bad"}"><main class="col"><div class="brand">${mark(38, 23, "c")}<span>HyperFrames</span></div><div class="tile">${args.ok ? CHECK : CROSS}</div><h1>${escapeHtml(args.title)}</h1><p>${escapeHtml(args.text)}</p>${detail}</main><aside class="panel"><div class="badge">${mark(96, 58, "p")}${CHK}</div><b>HyperFrames</b><small>by HeyGen</small></aside></body></html>`;
|
||||
}
|
||||
|
||||
export function connectedPage(): string {
|
||||
return page({
|
||||
ok: true,
|
||||
title: "You're connected",
|
||||
text: "Return to your terminal. You can close this tab.",
|
||||
});
|
||||
}
|
||||
|
||||
/** A Cancel says "Not authorized"; any other ending is a failure and says so. */
|
||||
export function failurePage(code: string, description: string): string {
|
||||
if (code === "access_denied") {
|
||||
return page({
|
||||
ok: false,
|
||||
title: "Not authorized",
|
||||
text: "Nothing was connected. Run the login again from your terminal.",
|
||||
});
|
||||
}
|
||||
return page({
|
||||
ok: false,
|
||||
title: "Couldn't connect",
|
||||
text:
|
||||
description ||
|
||||
"Something went wrong on the way back. Run the login again from your terminal.",
|
||||
detail: code,
|
||||
});
|
||||
}
|
||||
@@ -27,7 +27,7 @@ describe("auth/loopback", () => {
|
||||
expect(result.redirectUri).toContain(redirect.host);
|
||||
expect(res.status).toBe(200);
|
||||
const body = await res.text();
|
||||
expect(body).toContain("Signed in");
|
||||
expect(body).toContain("You're connected");
|
||||
});
|
||||
|
||||
async function expectRejection(args: {
|
||||
@@ -57,6 +57,29 @@ describe("auth/loopback", () => {
|
||||
});
|
||||
});
|
||||
|
||||
async function pageFor(query: string): Promise<string> {
|
||||
const handle = await startLoopback({ state: "s", timeoutMs: 5_000 });
|
||||
active = handle;
|
||||
handle.result.catch(() => {});
|
||||
const res = await fetch(`${handle.redirectUri}?${query}`);
|
||||
expect(res.status).toBe(400);
|
||||
return res.text();
|
||||
}
|
||||
|
||||
it("says Not authorized only when the person pressed Cancel", async () => {
|
||||
const body = await pageFor("error=access_denied&state=s");
|
||||
expect(body).toContain("Not authorized");
|
||||
expect(body).not.toContain("Couldn't connect");
|
||||
});
|
||||
|
||||
it("says Couldn't connect, with the code, for a failure that is not a Cancel", async () => {
|
||||
const body = await pageFor("error=server_error&error_description=try+later&state=s");
|
||||
expect(body).toContain("Couldn't connect");
|
||||
expect(body).toContain("server_error");
|
||||
expect(body).toContain("try later");
|
||||
expect(body).not.toContain("Not authorized");
|
||||
});
|
||||
|
||||
it("rejects when code is missing from the callback", async () => {
|
||||
await expectRejection({ expectedState: "s", query: "state=s", pattern: /code/ });
|
||||
});
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
import { timingSafeEqual } from "node:crypto";
|
||||
import { createServer, type IncomingMessage, type Server, type ServerResponse } from "node:http";
|
||||
import { AddressInfo } from "node:net";
|
||||
import { connectedPage, failurePage } from "./callbackPage.js";
|
||||
|
||||
export interface LoopbackOptions {
|
||||
/** Expected `state` value — flow fails if it doesn't match. */
|
||||
@@ -137,14 +138,14 @@ function handleRequest(
|
||||
const error = params.get("error");
|
||||
if (error) {
|
||||
const desc = params.get("error_description") ?? "";
|
||||
respond(res, 400, errorPage(error, desc));
|
||||
respond(res, 400, failurePage(error, desc));
|
||||
rejectResult(new Error(`OAuth authorize returned error: ${error}${desc ? ` — ${desc}` : ""}`));
|
||||
return;
|
||||
}
|
||||
|
||||
const state = params.get("state");
|
||||
if (!state || !stateMatches(state, expectedState)) {
|
||||
respond(res, 400, errorPage("invalid_state", "State parameter did not match."));
|
||||
respond(res, 400, failurePage("invalid_state", "State parameter did not match."));
|
||||
rejectResult(new Error("OAuth state mismatch — possible CSRF, aborting."));
|
||||
return;
|
||||
}
|
||||
@@ -154,13 +155,13 @@ function handleRequest(
|
||||
respond(
|
||||
res,
|
||||
400,
|
||||
errorPage("missing_code", "Authorization code is missing from the redirect."),
|
||||
failurePage("missing_code", "Authorization code is missing from the redirect."),
|
||||
);
|
||||
rejectResult(new Error("OAuth redirect did not include `code`."));
|
||||
return;
|
||||
}
|
||||
|
||||
respond(res, 200, successPage());
|
||||
respond(res, 200, connectedPage());
|
||||
resolveResult({ code, redirectUri });
|
||||
}
|
||||
|
||||
@@ -191,26 +192,3 @@ function respond(res: ServerResponse, status: number, body: string): void {
|
||||
})
|
||||
.end(body);
|
||||
}
|
||||
|
||||
function successPage(): string {
|
||||
return `<!doctype html><html><head><meta charset="utf-8"><title>Signed in to HyperFrames</title>
|
||||
<style>body{font-family:system-ui,sans-serif;display:flex;align-items:center;justify-content:center;height:100vh;margin:0;background:#0b0f14;color:#e6e8eb}main{max-width:480px;text-align:center;padding:32px;border-radius:12px;background:#11161d;border:1px solid #1f2630}h1{font-weight:600;margin:0 0 8px;color:#3CE6AC}p{margin:0;color:#9aa3ad}</style>
|
||||
</head><body><main><h1>You're signed in.</h1><p>You can close this tab and return to your terminal.</p></main></body></html>`;
|
||||
}
|
||||
|
||||
function errorPage(code: string, description: string): string {
|
||||
const safeCode = escapeHtml(code);
|
||||
const safeDesc = escapeHtml(description);
|
||||
return `<!doctype html><html><head><meta charset="utf-8"><title>Sign-in failed</title>
|
||||
<style>body{font-family:system-ui,sans-serif;display:flex;align-items:center;justify-content:center;height:100vh;margin:0;background:#1a0b0b;color:#e6e8eb}main{max-width:480px;text-align:center;padding:32px;border-radius:12px;background:#1d1111;border:1px solid #301f1f}h1{font-weight:600;margin:0 0 8px;color:#ff7a7a}code{background:#2a1414;padding:2px 6px;border-radius:4px}p{margin:8px 0 0;color:#9aa3ad}</style>
|
||||
</head><body><main><h1>Sign-in failed</h1><p><code>${safeCode}</code></p><p>${safeDesc}</p></main></body></html>`;
|
||||
}
|
||||
|
||||
function escapeHtml(s: string): string {
|
||||
return s
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user