reafctor(haveibeenpwned): add try catch and timeout

This commit is contained in:
Bereket Engida
2025-11-20 14:27:45 -08:00
parent 9ca43e3372
commit 2c2b990aa2

View File

@@ -29,6 +29,7 @@ async function checkPasswordCompromise(
"Add-Padding": "true",
"User-Agent": "BetterAuth Password Checker",
},
timeout: 5000, // 5s timeout
},
);
@@ -81,15 +82,19 @@ export const haveIBeenPwned = (options?: HaveIBeenPwnedOptions | undefined) => {
password: {
...ctx.password,
async hash(password) {
const c = await getCurrentAuthContext();
if (!c.path || !paths.includes(c.path)) {
try {
const c = await getCurrentAuthContext();
if (!c.path || !paths.includes(c.path)) {
return ctx.password.hash(password);
}
await checkPasswordCompromise(
password,
options?.customPasswordCompromisedMessage,
);
return ctx.password.hash(password);
} catch (e) {
return ctx.password.hash(password);
}
await checkPasswordCompromise(
password,
options?.customPasswordCompromisedMessage,
);
return ctx.password.hash(password);
},
},
},