diff --git a/src/lib/server/services/schedule-service.ts b/src/lib/server/services/schedule-service.ts index b0034d8..b2af647 100644 --- a/src/lib/server/services/schedule-service.ts +++ b/src/lib/server/services/schedule-service.ts @@ -169,10 +169,10 @@ export class ScheduleService { let staffKeyShares: Record = {}; // Tunnel keys are wrapped per passkey; scope the lookup to the passkey the user most // recently authenticated with (same definition getClientTunnels / key-shard use). - const recentPasskey = request.staffUserId + const currentPasskey = request.staffUserId ? await WebAuthnService.getCurrentPasskey(request.staffUserId, passkeyId) : null; - if (request.staffUserId && recentPasskey && appointments.length > 0) { + if (request.staffUserId && currentPasskey && appointments.length > 0) { const tunnelIds = [...new Set(appointments.map((apt) => apt.tunnelId))]; const keyShares = await db .select() @@ -180,7 +180,7 @@ export class ScheduleService { .where( and( eq(tenantSchema.clientTunnelStaffKeyShare.userId, request.staffUserId), - eq(tenantSchema.clientTunnelStaffKeyShare.passkeyId, recentPasskey.id), + eq(tenantSchema.clientTunnelStaffKeyShare.passkeyId, currentPasskey.id), inArray(tenantSchema.clientTunnelStaffKeyShare.tunnelId, tunnelIds), ), ); diff --git a/src/routes/api/tenants/[id]/staff/[staffId]/key-shard/+server.ts b/src/routes/api/tenants/[id]/staff/[staffId]/key-shard/+server.ts index 7b68f35..cf6158f 100644 --- a/src/routes/api/tenants/[id]/staff/[staffId]/key-shard/+server.ts +++ b/src/routes/api/tenants/[id]/staff/[staffId]/key-shard/+server.ts @@ -148,12 +148,12 @@ export const GET: RequestHandler = async ({ params, locals }) => { try { // Get the most recently used passkey for this authenticated user - const recentPasskey = await WebAuthnService.getCurrentPasskey( + const currentPasskey = await WebAuthnService.getCurrentPasskey( locals.user.id, locals.user?.passkeyId, ); - if (!recentPasskey) { + if (!currentPasskey) { log.warn("No passkey found for authenticated user - security violation", { tenantId, staffId, @@ -163,12 +163,12 @@ export const GET: RequestHandler = async ({ params, locals }) => { throw new AuthorizationError("No valid passkey found for authenticated user"); } - passkeyId = recentPasskey.id; + passkeyId = currentPasskey.id; log.debug("Using authenticated user's most recent passkey", { tenantId, staffId, passkeyId, - lastUsedAt: recentPasskey.lastUsedAt, + lastUsedAt: currentPasskey.lastUsedAt, }); } catch (error) { if (error instanceof AuthorizationError) {