Skip to content

Commit 4e8b12f

Browse files
committed
perf: dont make db calls for guests and spiders
1 parent 0911dc0 commit 4e8b12f

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

library.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,24 @@ plugin.saveAuthn = (uid, authnrData) => {
245245
db.sortedSetAdd(`2factor:webauthn:counters`, counter, id);
246246
};
247247

248-
plugin.hasAuthn = async uid => db.exists(`2factor:webauthn:${uid}`);
248+
plugin.hasAuthn = async (uid) => {
249+
if (!(parseInt(uid, 10) > 0)) {
250+
return false;
251+
}
252+
return await db.exists(`2factor:webauthn:${uid}`);
253+
};
249254

250-
plugin.hasTotp = async uid => db.isObjectField('2factor:uid:key', uid);
255+
plugin.hasTotp = async (uid) => {
256+
if (!(parseInt(uid, 10) > 0)) {
257+
return false;
258+
}
259+
return await db.isObjectField('2factor:uid:key', uid);
260+
};
251261

252262
// hmm... remove?
253263
plugin.hasKey = async (uid) => {
254264
const [hasTotp, hasAuthn] = await Promise.all([
255-
db.isObjectField('2factor:uid:key', uid),
265+
plugin.hasTotp(uid),
256266
plugin.hasAuthn(uid),
257267
]);
258268

0 commit comments

Comments
 (0)