INNER CODE UNIT · TypeScript

wait

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

  const wait = options.sleep ?? ((ms: number) => defaultSleep(ms, options.signal));
  const baseURL = options.baseURL.replace(/\/$/, "");
  // Device codes never follow redirects: a redirected endpoint is not the
  // control plane the user asked to sign in to.
  const codeResponse = await fetcher(`${baseURL}/api/v1/auth/device/code`, {
    method: "POST",
    redirect: "error",
    headers: { "content-type": "application/json", "x-cave-client": options.client },
    body: "{}",
    signal: requestSignal(options.signal, 5000),
  });
  if (!codeResponse.ok) {
    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" ||

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…