rebreak-monorepo/backend/server/api/devices/[id]/confirm-installed.post.ts
chahinebrini 677b67902b feat(devices): protected device enrollment + mobileconfig generator
Backend:
- ProtectedDevice prisma model + migration add_protected_devices
- DB helpers: list/count/get/create/confirm/revoke
- mobileconfig.ts utility — XML-escape, unique UUIDs per request
- 5 endpoints under /api/devices/* (avoid /api/devices conflict with existing
  Capacitor UserDevice route by using /api/devices/protected for list)

Phase 1: backend ready. DoH-server token-routing comes in phase 2.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 04:06:49 +02:00

27 lines
861 B
TypeScript

import { confirmProtectedDeviceInstalled } from "../../../db/protectedDevices";
/**
* POST /api/devices/:id/confirm-installed
*
* User klickt "Installiert" in der App nach dem Profil-Download.
* Setzt installedAt = NOW() und status = "active".
*
* Auth: requireUser + ownership (confirmProtectedDeviceInstalled prüft userId).
*/
export default defineEventHandler(async (event) => {
const user = await requireUser(event);
const id = getRouterParam(event, "id");
if (!id) throw createError({ statusCode: 400, data: { error: "ID_REQUIRED" } });
const updated = await confirmProtectedDeviceInstalled(id, user.id);
if (!updated) {
throw createError({
statusCode: 404,
data: { error: "DEVICE_NOT_FOUND_OR_REVOKED" },
});
}
return { success: true, data: { status: updated.status, installedAt: updated.installedAt } };
});