update user schema, webauthn bug fix

This commit is contained in:
2025-02-24 16:56:25 +05:30
parent dee35bec5b
commit fef560127a
8 changed files with 22 additions and 6 deletions

View File

@@ -51,8 +51,10 @@ export async function webAuthnRoutes(fastify: FastifyInstance) {
userName: email,
attestationType: "none",
excludeCredentials: userInDB.passKeys.map((cred) => ({
// @ts-ignore
id: cred.credentialID,
type: "public-key",
// @ts-ignore
transports: cred.transports,
})),
});
@@ -96,7 +98,7 @@ export async function webAuthnRoutes(fastify: FastifyInstance) {
properties: {
email: { type: "string" },
code: { type: "string" },
attestationResponse: { type: "object" },
attestationResponse: { type: "object", additionalProperties: true },
},
},
},
@@ -174,8 +176,10 @@ export async function webAuthnRoutes(fastify: FastifyInstance) {
await generateAuthenticationOptions({
rpID,
allowCredentials: userInDB.passKeys.map((cred) => ({
// @ts-ignore
id: cred.credentialID,
type: "public-key",
// @ts-ignore
transports: cred.transports,
})),
userVerification: "preferred",
@@ -218,6 +222,7 @@ export async function webAuthnRoutes(fastify: FastifyInstance) {
try {
const credential = userInDB.passKeys.find(
// @ts-ignore
(cred) => cred.credentialID === assertionResponse.id
);
@@ -230,12 +235,14 @@ export async function webAuthnRoutes(fastify: FastifyInstance) {
expectedChallenge: userInDB.challenge.value as string,
expectedRPID: rpID,
expectedOrigin: origin,
// @ts-ignore
credential: credential,
});
if (!verification.verified)
return res.code(400).send({ error: "Authentication failed" });
// @ts-ignore
credential.counter = verification.authenticationInfo.newCounter;
const newSession = await createSession(