{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../src/astro/routes/api/auth/passkey/index.ts"],"sourcesContent":["/**\n * GET /_emdash/api/auth/passkey\n *\n * List all passkeys for the authenticated user\n */\n\nimport type { APIRoute } from \"astro\";\n\nexport const prerender = false;\n\nimport { createKyselyAdapter } from \"@premium-cms/auth/adapters/kysely\";\n\nimport { apiError, apiSuccess, handleError } from \"#api/error.js\";\n\ninterface PasskeyResponse {\n\tid: string;\n\tname: string | null;\n\tdeviceType: \"singleDevice\" | \"multiDevice\";\n\tbackedUp: boolean;\n\tcreatedAt: string;\n\tlastUsedAt: string;\n}\n\nexport const GET: APIRoute = async ({ locals }) => {\n\tconst { emdash, user } = locals;\n\n\tif (!emdash?.db) {\n\t\treturn apiError(\"NOT_CONFIGURED\", \"EmDash is not initialized\", 500);\n\t}\n\n\t// Require authentication\n\tif (!user) {\n\t\treturn apiError(\"NOT_AUTHENTICATED\", \"Not authenticated\", 401);\n\t}\n\n\ttry {\n\t\tconst adapter = createKyselyAdapter(emdash.db);\n\t\tconst credentials = await adapter.getCredentialsByUserId(user.id);\n\n\t\t// Map to public response format (exclude sensitive fields)\n\t\tconst passkeys: PasskeyResponse[] = credentials.map((cred) => ({\n\t\t\tid: cred.id,\n\t\t\tname: cred.name,\n\t\t\tdeviceType: cred.deviceType,\n\t\t\tbackedUp: cred.backedUp,\n\t\t\tcreatedAt: cred.createdAt.toISOString(),\n\t\t\tlastUsedAt: cred.lastUsedAt.toISOString(),\n\t\t}));\n\n\t\treturn apiSuccess({ items: passkeys });\n\t} catch (error) {\n\t\treturn handleError(error, \"Failed to list passkeys\", \"PASSKEY_LIST_ERROR\");\n\t}\n};\n"],"mappings":";;;;;;AAQA,MAAa,YAAY;AAezB,MAAa,MAAgB,OAAO,EAAE,aAAa;CAClD,MAAM,EAAE,QAAQ,SAAS;AAEzB,KAAI,CAAC,QAAQ,GACZ,QAAO,SAAS,kBAAkB,6BAA6B,IAAI;AAIpE,KAAI,CAAC,KACJ,QAAO,SAAS,qBAAqB,qBAAqB,IAAI;AAG/D,KAAI;AAcH,SAAO,WAAW,EAAE,QAZA,MADJ,oBAAoB,OAAO,GAAG,CACZ,uBAAuB,KAAK,GAAG,EAGjB,KAAK,UAAU;GAC9D,IAAI,KAAK;GACT,MAAM,KAAK;GACX,YAAY,KAAK;GACjB,UAAU,KAAK;GACf,WAAW,KAAK,UAAU,aAAa;GACvC,YAAY,KAAK,WAAW,aAAa;GACzC,EAAE,EAEkC,CAAC;UAC9B,OAAO;AACf,SAAO,YAAY,OAAO,2BAA2B,qBAAqB"}