INNER CODE UNIT · TypeScript

body

JuliusBrussee/caveman · packages/device-auth/src/index.ts:135

    const body = await codeResponse.json().catch(() => null);
    throw new DeviceAuthError(`device authorization failed: HTTP ${codeResponse.status}`, codeResponse.status, errorCode(body));
  }
  const rawCode = await codeResponse.json().catch(() => null) as Partial<DeviceCode> | null;
  if (rawCode === null || typeof rawCode.device_code !== "string" || rawCode.device_code === "" ||
    typeof rawCode.user_code !== "string" || typeof rawCode.verification_uri !== "string" ||
    typeof rawCode.expires_in !== "number" || !Number.isFinite(rawCode.expires_in) || rawCode.expires_in <= 0) {
    throw new Error(`device authorization failed: ${JSON.stringify(rawCode)}`);
  }
  const code = rawCode as DeviceCode;
  await options.onCode?.(structuredClone(code));
  let intervalMs = Math.max(0, Number(code.interval ?? 5)) * 1000;
  const deadline = Date.now() + code.expires_in * 1000;
  while (Date.now() < deadline) {
    let payload: Record<string, unknown>;
    let status = 0;
    let retryAfterMs = 0;
    try {

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…