import { NextResponse } from "next/server"; import { query } from "@/lib/db"; import { requireSession, UnauthorizedError } from "@/lib/auth/session"; export async function GET() { try { const session = await requireSession(); const rows = await query<{ id: string; name: string | null; created_at: string; last_used_at: string | null; }>( `select id, name, created_at, last_used_at from passkey_credentials where user_id = $1 order by created_at`, [session.user.id] ); return NextResponse.json(rows); } catch (err) { if (err instanceof UnauthorizedError) { return NextResponse.json({ error: "unauthorized" }, { status: 401 }); } throw err; } }