fix(backend): remove hardwareId references, use deviceId only
This commit is contained in:
parent
a60def33d9
commit
943efe4b45
@ -32,7 +32,6 @@ export default defineEventHandler(async (event) => {
|
|||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
deviceId: true,
|
deviceId: true,
|
||||||
hardwareId: true,
|
|
||||||
platform: true,
|
platform: true,
|
||||||
model: true,
|
model: true,
|
||||||
name: true,
|
name: true,
|
||||||
@ -66,7 +65,6 @@ export default defineEventHandler(async (event) => {
|
|||||||
return {
|
return {
|
||||||
source: "magic" as const,
|
source: "magic" as const,
|
||||||
deviceId: d.deviceId,
|
deviceId: d.deviceId,
|
||||||
hardwareId: d.hardwareId,
|
|
||||||
hostname: d.hostname ?? "Unbenanntes Ger\u00e4t",
|
hostname: d.hostname ?? "Unbenanntes Ger\u00e4t",
|
||||||
model: d.model,
|
model: d.model,
|
||||||
osVersion: d.osVersion,
|
osVersion: d.osVersion,
|
||||||
@ -90,7 +88,6 @@ export default defineEventHandler(async (event) => {
|
|||||||
return {
|
return {
|
||||||
source: "locked" as const,
|
source: "locked" as const,
|
||||||
deviceId: d.deviceId,
|
deviceId: d.deviceId,
|
||||||
hardwareId: d.hardwareId,
|
|
||||||
hostname: d.name ?? d.model ?? prettyPlatform(d.platform),
|
hostname: d.name ?? d.model ?? prettyPlatform(d.platform),
|
||||||
model: d.model,
|
model: d.model,
|
||||||
osVersion: d.osVersion,
|
osVersion: d.osVersion,
|
||||||
|
|||||||
@ -22,9 +22,8 @@ import { generateRemovalPassword } from "../../utils/magic-lock";
|
|||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const user = await requireUser(event);
|
const user = await requireUser(event);
|
||||||
const body = await readBody(event);
|
const body = await readBody(event);
|
||||||
const { deviceId, hardwareId, hostname, model, osVersion, platform } = body as {
|
const { deviceId, hostname, model, osVersion, platform } = body as {
|
||||||
deviceId?: string;
|
deviceId?: string;
|
||||||
hardwareId?: string;
|
|
||||||
hostname?: string;
|
hostname?: string;
|
||||||
model?: string;
|
model?: string;
|
||||||
osVersion?: string;
|
osVersion?: string;
|
||||||
@ -38,16 +37,14 @@ export default defineEventHandler(async (event) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!deviceId && !hardwareId) {
|
if (!deviceId) {
|
||||||
throw createError({
|
throw createError({
|
||||||
statusCode: 400,
|
statusCode: 400,
|
||||||
message: "deviceId oder hardwareId required",
|
message: "deviceId required",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Für neue Magic-Registrierungen: hardwareId wird gleichzeitig deviceId,
|
const effectiveDeviceId = deviceId.trim();
|
||||||
// damit das Backend keine eigene ID generieren muss.
|
|
||||||
const effectiveDeviceId = deviceId?.trim() || hardwareId!.trim();
|
|
||||||
|
|
||||||
// Plattform: Mac-App sendet nichts (legacy default), Windows-App sendet "windows"
|
// Plattform: Mac-App sendet nichts (legacy default), Windows-App sendet "windows"
|
||||||
const devicePlatform =
|
const devicePlatform =
|
||||||
@ -56,60 +53,18 @@ export default defineEventHandler(async (event) => {
|
|||||||
const db = usePrisma();
|
const db = usePrisma();
|
||||||
|
|
||||||
// 1. Prüfe ob Device bereits als Magic-Client gebunden ist (idempotent)
|
// 1. Prüfe ob Device bereits als Magic-Client gebunden ist (idempotent)
|
||||||
// Priorität: hardwareId → deviceId → Migration über Modell/Plattform/OS.
|
let existing = await db.userDevice.findUnique({
|
||||||
let existing = null;
|
where: { userId_deviceId: { userId: user.id, deviceId } },
|
||||||
|
select: {
|
||||||
if (hardwareId) {
|
id: true,
|
||||||
existing = await db.userDevice.findFirst({
|
userId: true,
|
||||||
where: { userId: user.id, hardwareId },
|
deviceId: true,
|
||||||
select: {
|
magicDnsToken: true,
|
||||||
id: true,
|
magicEnrolledAt: true,
|
||||||
userId: true,
|
magicRevokedAt: true,
|
||||||
deviceId: true,
|
magicRemovalPassword: true,
|
||||||
magicDnsToken: true,
|
},
|
||||||
magicEnrolledAt: true,
|
});
|
||||||
magicRevokedAt: true,
|
|
||||||
magicRemovalPassword: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!existing && deviceId) {
|
|
||||||
existing = await db.userDevice.findUnique({
|
|
||||||
where: { userId_deviceId: { userId: user.id, deviceId } },
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
userId: true,
|
|
||||||
deviceId: true,
|
|
||||||
magicDnsToken: true,
|
|
||||||
magicEnrolledAt: true,
|
|
||||||
magicRevokedAt: true,
|
|
||||||
magicRemovalPassword: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Migration: bestehendes Gerät ohne hardwareId anhand von Modell/Plattform/OS finden.
|
|
||||||
if (!existing && hardwareId) {
|
|
||||||
existing = await db.userDevice.findFirst({
|
|
||||||
where: {
|
|
||||||
userId: user.id,
|
|
||||||
hardwareId: null,
|
|
||||||
platform: devicePlatform,
|
|
||||||
model: model ?? null,
|
|
||||||
osVersion: osVersion ?? null,
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
userId: true,
|
|
||||||
deviceId: true,
|
|
||||||
magicDnsToken: true,
|
|
||||||
magicEnrolledAt: true,
|
|
||||||
magicRevokedAt: true,
|
|
||||||
magicRemovalPassword: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wenn Token existiert und nicht revoked → return existing
|
// Wenn Token existiert und nicht revoked → return existing
|
||||||
if (
|
if (
|
||||||
@ -199,14 +154,12 @@ export default defineEventHandler(async (event) => {
|
|||||||
model: model ?? null,
|
model: model ?? null,
|
||||||
name: hostname,
|
name: hostname,
|
||||||
osVersion: osVersion ?? null,
|
osVersion: osVersion ?? null,
|
||||||
hardwareId: hardwareId ?? null,
|
|
||||||
magicDnsToken: dnsToken,
|
magicDnsToken: dnsToken,
|
||||||
magicEnrolledAt: new Date(),
|
magicEnrolledAt: new Date(),
|
||||||
magicHostname: hostname,
|
magicHostname: hostname,
|
||||||
magicRemovalPassword: removalPassword,
|
magicRemovalPassword: removalPassword,
|
||||||
},
|
},
|
||||||
update: {
|
update: {
|
||||||
hardwareId: hardwareId ?? undefined,
|
|
||||||
magicDnsToken: dnsToken,
|
magicDnsToken: dnsToken,
|
||||||
magicEnrolledAt: new Date(),
|
magicEnrolledAt: new Date(),
|
||||||
magicRevokedAt: null, // Clear falls vorher revoked
|
magicRevokedAt: null, // Clear falls vorher revoked
|
||||||
|
|||||||
@ -418,7 +418,6 @@ export async function deleteUserDevice(
|
|||||||
|
|
||||||
export interface MagicDeviceRecord {
|
export interface MagicDeviceRecord {
|
||||||
deviceId: string;
|
deviceId: string;
|
||||||
hardwareId: string | null;
|
|
||||||
hostname: string | null;
|
hostname: string | null;
|
||||||
model: string | null;
|
model: string | null;
|
||||||
osVersion: string | null;
|
osVersion: string | null;
|
||||||
@ -447,7 +446,6 @@ export async function listMagicDevices(
|
|||||||
orderBy: { magicEnrolledAt: "desc" },
|
orderBy: { magicEnrolledAt: "desc" },
|
||||||
select: {
|
select: {
|
||||||
deviceId: true,
|
deviceId: true,
|
||||||
hardwareId: true,
|
|
||||||
magicHostname: true,
|
magicHostname: true,
|
||||||
model: true,
|
model: true,
|
||||||
osVersion: true,
|
osVersion: true,
|
||||||
@ -462,7 +460,6 @@ export async function listMagicDevices(
|
|||||||
|
|
||||||
return devices.map((d) => ({
|
return devices.map((d) => ({
|
||||||
deviceId: d.deviceId,
|
deviceId: d.deviceId,
|
||||||
hardwareId: d.hardwareId,
|
|
||||||
hostname: d.magicHostname,
|
hostname: d.magicHostname,
|
||||||
model: d.model,
|
model: d.model,
|
||||||
osVersion: d.osVersion,
|
osVersion: d.osVersion,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user