🪻 distributed transcription service thistle.dunkirk.sh

fix: return error instead of throwing for passkey not found

🪻 Generated with Crush

Co-Authored-By: Crush <crush@charm.land>

dunkirk.sh a7bdc127 b181acbe

verified
Changed files
+11 -3
src
+9 -1
src/index.ts
···
const body = await req.json();
const { response: credentialResponse, challenge } = body;
-
const { user } = await verifyAndAuthenticatePasskey(
credentialResponse,
challenge,
);
// Create session
const ipAddress =
···
const body = await req.json();
const { response: credentialResponse, challenge } = body;
+
const result = await verifyAndAuthenticatePasskey(
credentialResponse,
challenge,
);
+
+
if ("error" in result) {
+
return new Response(JSON.stringify({ error: result.error }), {
+
status: 401,
+
});
+
}
+
+
const { user } = result;
// Create session
const ipAddress =
+2 -2
src/lib/passkey.ts
···
export async function verifyAndAuthenticatePasskey(
response: AuthenticationResponseJSON,
expectedChallenge: string,
-
): Promise<{ passkey: Passkey; user: User }> {
// Validate challenge
const challengeData = authenticationChallenges.get(expectedChallenge);
if (!challengeData) {
···
.get(response.id);
if (!passkey) {
-
throw new Error("Passkey not found");
}
const { origin, rpID } = getRPConfig();
···
export async function verifyAndAuthenticatePasskey(
response: AuthenticationResponseJSON,
expectedChallenge: string,
+
): Promise<{ passkey: Passkey; user: User } | { error: string }> {
// Validate challenge
const challengeData = authenticationChallenges.get(expectedChallenge);
if (!challengeData) {
···
.get(response.id);
if (!passkey) {
+
return { error: "Passkey not found" };
}
const { origin, rpID } = getRPConfig();