mirror of
https://github.com/open-reception/appointment-booking-software.git
synced 2026-10-01 05:04:50 +02:00
Harden passkey management
This commit is contained in:
+11
@@ -167,6 +167,17 @@
|
||||
} catch (error) {
|
||||
console.error("Unable to add passkey", error);
|
||||
toast.error(m["account.passkeys.add.error"]());
|
||||
|
||||
// Try to delete the partially added passkey if it was created
|
||||
await fetch(`/api/auth/passkeys/${$formData.id}`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ tenantId }),
|
||||
credentials: "same-origin",
|
||||
});
|
||||
toast.info(m["account.passkeys.add.errorDeleteSuccess"]());
|
||||
} finally {
|
||||
isSubmitting = false;
|
||||
}
|
||||
|
||||
@@ -229,10 +229,12 @@ export const POST: RequestHandler = async ({ request, cookies, url }) => {
|
||||
// Try to get user by email - but don't fail if not found
|
||||
let user = null;
|
||||
let isRegistration = false;
|
||||
let passkeysLength = 0;
|
||||
|
||||
try {
|
||||
user = await UserService.getUserByEmail(requestEmail);
|
||||
const passkeys = await UserService.getUserPasskeys(user.id);
|
||||
passkeysLength = passkeys.length;
|
||||
if (passkeys.length === 0) {
|
||||
isRegistration = true; // User exists but has no passphrase - must register
|
||||
}
|
||||
@@ -279,6 +281,10 @@ export const POST: RequestHandler = async ({ request, cookies, url }) => {
|
||||
path: "/",
|
||||
maxAge: 60 * 5, // 5 minutes
|
||||
});
|
||||
} else {
|
||||
if (passkeysLength >= 3) {
|
||||
throw new BackendError("Maximum number of passkeys reached", 400);
|
||||
}
|
||||
}
|
||||
|
||||
let allowCredentials: Array<{
|
||||
|
||||
Reference in New Issue
Block a user