{"record":{"id":"e6fbe398fd4ba6a6","repo":"QuantumNous/new-api","slug":"unable-to-parse-passkey-registration-options-from","errorCode":null,"errorMessage":"Unable to parse Passkey registration options from response","messagePattern":"Unable to parse Passkey registration options from response","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"web/src/lib/passkey.ts","lineNumber":117,"sourceCode":"    .replace(/\\+/g, '-')\n    .replace(/\\//g, '_')\n    .replace(/=+$/g, '')\n}\n\n/**\n * Prepare credential creation options returned by the backend.\n */\nexport function prepareCredentialCreationOptions(\n  payload: any\n): PublicKeyCredentialCreationOptions {\n  const options =\n    payload?.publicKey ??\n    payload?.PublicKey ??\n    payload?.response ??\n    payload?.Response\n\n  if (!options) {\n    throw new Error(\n      'Unable to parse Passkey registration options from response'\n    )\n  }\n\n  const publicKey: PublicKeyCredentialCreationOptions & Record<string, any> = {\n    ...options,\n    challenge: base64UrlToArrayBuffer(options.challenge),\n    user: {\n      ...options.user,\n      id: base64UrlToArrayBuffer(options.user?.id),\n    },\n  }\n\n  if (Array.isArray(options.excludeCredentials)) {\n    publicKey.excludeCredentials = options.excludeCredentials.map(\n      (item: any) => ({\n        ...item,\n        id: base64UrlToArrayBuffer(item.id),","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/QuantumNous/new-api/blob/e2c7aa7b102c2075eae2377df3508658d45e88dc/web/src/lib/passkey.ts#L99-L135","documentation":"Thrown by prepareCredentialCreationOptions in the passkey lib when the backend's registration-options payload contains none of the recognized shapes: top-level publicKey, PublicKey, response, or Response. The WebAuthn navigator.credentials.create call needs a PublicKeyCredentialCreationOptions object; without one, registration cannot proceed and the parser refuses to guess.","triggerScenarios":"Calling prepareCredentialCreationOptions(payload) where payload is null/undefined, an error envelope ({success:false}), or a registration-begin response whose options live under a new/unexpected key.","commonSituations":"Backend returns {success:false} (session expired before registration start) and the caller passes res.data (undefined) through; API version change renaming the options field; response wrapped one level deeper than expected.","solutions":["Log the payload keys at the call site and compare with the four accepted fields (publicKey/PublicKey/response/Response).","Check the registration-begin request actually succeeded before parsing — a failed begin with success:false must not reach this function.","If the backend nests options differently, extend the lookup (or better, fix the backend contract) and add a fixture test for that shape.","Handle the throw with a user-facing 'Passkey registration failed, try again' message."],"exampleFix":"// before\nconst publicKey = prepareCredentialCreationOptions(begin.data)\n\n// after — guard the envelope before parsing\nif (!begin.success || !begin.data) {\n  throw new Error(begin.message || 'Failed to start Passkey registration')\n}\nconst publicKey = prepareCredentialCreationOptions(begin.data)","handlingStrategy":"type-guard","validationCode":"if (!payload || !(payload.publicKey ?? payload.PublicKey ?? payload.response ?? payload.Response)) {\n  // show 'Passkey registration unavailable' and fall back; do not call the parser\n}","typeGuard":"function hasCreationOptions(payload: any): boolean {\n  return Boolean(payload?.publicKey ?? payload?.PublicKey ?? payload?.response ?? payload?.Response)\n}","tryCatchPattern":"try {\n  const publicKey = prepareCredentialCreationOptions(payload)\n} catch (error) {\n  if (/Unable to parse Passkey registration options/.test(error.message)) {\n    // log payload shape, show retry UI, keep password/OTP signup available\n  }\n}","preventionTips":["Always check the begin-registration response's success flag before parsing","Keep a fixture test of the backend's actual registration payload next to the parser"],"tags":["passkey","webauthn","registration","payload-shape"],"backgroundTag":null,"analyzedSha":"e2c7aa7b102c2075eae2377df3508658d45e88dc","analyzedAt":"2026-08-15T10:35:18.111Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}