mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 23:52:24 +00:00
feat(passkeys): surface last-used, rename, and an upgrade nudge
Stamp each passkey's last-used time on a successful assertion and return it from the list, add a rename endpoint, and add a dismissible add-a-passkey nudge for accounts that have none. Share the relying-party configuration with the second-factor path.
This commit is contained in:
1 parent
86ac1e1d12
commit
64ea8e4102
4 files changed
+93
-36
No files matched your search
+14
-35
@@ -10,6 +10,11 @@ import {
|
||||
} from "@simplewebauthn/server";
|
||||
import { z } from "zod/v4";
|
||||
import { prisma } from "@/lib/db";
|
||||
import {
|
||||
RP_NAME as rpName,
|
||||
getRpId,
|
||||
getExpectedOrigin,
|
||||
} from "@/lib/auth/webauthn-rp";
|
||||
|
||||
// v1.4.43 W13 L-3 — explicit Zod narrowing in front of
|
||||
// `verifyAuthentication`. Replaces the raw
|
||||
@@ -76,7 +81,9 @@ type Transport =
|
||||
| "smart-card"
|
||||
| "usb";
|
||||
|
||||
const rpName = "HealthLog";
|
||||
// The relying-party config (`rpName` / `getRpId` / `getExpectedOrigin`) is
|
||||
// shared with the second-factor security-key path via `@/lib/auth/webauthn-rp`
|
||||
// so both ceremonies bind credentials to the identical RP.
|
||||
|
||||
async function cleanupExpiredChallenges() {
|
||||
await prisma.authChallenge.deleteMany({
|
||||
@@ -84,38 +91,6 @@ async function cleanupExpiredChallenges() {
|
||||
});
|
||||
}
|
||||
|
||||
function getConfiguredOrigins(): string[] {
|
||||
const candidates = [
|
||||
process.env.APP_URL,
|
||||
process.env.NEXT_PUBLIC_APP_URL,
|
||||
"http://localhost:3000",
|
||||
]
|
||||
.map((value) => value?.trim())
|
||||
.filter((value): value is string => Boolean(value));
|
||||
|
||||
const validOrigins = candidates
|
||||
.map((value) => {
|
||||
try {
|
||||
return new URL(value).origin;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter((value): value is string => Boolean(value));
|
||||
|
||||
return Array.from(new Set(validOrigins));
|
||||
}
|
||||
|
||||
function getRpId(): string {
|
||||
const origins = getConfiguredOrigins();
|
||||
return new URL(origins[0]).hostname;
|
||||
}
|
||||
|
||||
function getExpectedOrigin(): string | string[] {
|
||||
const origins = getConfiguredOrigins();
|
||||
return origins.length === 1 ? origins[0] : origins;
|
||||
}
|
||||
|
||||
// ── Registration ─────────────────────────────────────────
|
||||
|
||||
export async function createRegistrationOptions(
|
||||
@@ -294,10 +269,14 @@ export async function verifyAuthentication(
|
||||
});
|
||||
|
||||
if (verification.verified) {
|
||||
// Update counter
|
||||
// Update counter + stamp last-used so the management UI can surface
|
||||
// when each passkey was last exercised (v1.23 passkey QoL).
|
||||
await prisma.passkey.update({
|
||||
where: { id: passkey.id },
|
||||
data: { counter: BigInt(verification.authenticationInfo.newCounter) },
|
||||
data: {
|
||||
counter: BigInt(verification.authenticationInfo.newCounter),
|
||||
lastUsedAt: new Date(),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user