replace debug() with our custom logger
mostly we want trace() and log(). trace() can be enabled whenever we want by flipping a flag and restarting box
This commit is contained in:
+10
-10
@@ -3,7 +3,7 @@ import BoxError from './boxerror.js';
|
||||
import crypto from 'node:crypto';
|
||||
import dashboard from './dashboard.js';
|
||||
import database from './database.js';
|
||||
import debugModule from 'debug';
|
||||
import logger from './logger.js';
|
||||
import safe from 'safetydance';
|
||||
import {
|
||||
generateRegistrationOptions,
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
} from '@simplewebauthn/server';
|
||||
import _ from './underscore.js';
|
||||
|
||||
const debug = debugModule('box:passkeys');
|
||||
const { log, trace } = logger('passkeys');
|
||||
|
||||
const PASSKEY_FIELDS = [ 'id', 'userId', 'credentialId', 'publicKey', 'counter', 'transports', 'name', 'creationTime', 'lastUsedTime' ].join(',');
|
||||
|
||||
@@ -151,7 +151,7 @@ async function getRegistrationOptions(user) {
|
||||
|
||||
storeChallenge(user.id, options.challenge);
|
||||
|
||||
debug(`getRegistrationOptions: generated for user ${user.id}`);
|
||||
log(`getRegistrationOptions: generated for user ${user.id}`);
|
||||
|
||||
return options;
|
||||
}
|
||||
@@ -179,7 +179,7 @@ async function verifyRegistration(user, response, name) {
|
||||
}));
|
||||
|
||||
if (error) {
|
||||
debug(`verifyRegistration: verification failed for user ${user.id}:`, error);
|
||||
log(`verifyRegistration: verification failed for user ${user.id}:`, error);
|
||||
throw new BoxError(BoxError.INVALID_CREDENTIALS, 'Passkey verification failed');
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ async function verifyRegistration(user, response, name) {
|
||||
name || 'Passkey'
|
||||
);
|
||||
|
||||
debug(`verifyRegistration: passkey registered for user ${user.id}`);
|
||||
log(`verifyRegistration: passkey registered for user ${user.id}`);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -224,7 +224,7 @@ async function getAuthenticationOptions(user) {
|
||||
|
||||
storeChallenge(user.id, options.challenge);
|
||||
|
||||
debug(`getAuthenticationOptions: generated for user ${user.id}`);
|
||||
log(`getAuthenticationOptions: generated for user ${user.id}`);
|
||||
|
||||
return options;
|
||||
}
|
||||
@@ -243,12 +243,12 @@ async function verifyAuthentication(user, response) {
|
||||
const passkey = await getByCredentialId(credentialIdBase64url);
|
||||
|
||||
if (!passkey) {
|
||||
debug(`verifyAuthentication: passkey not found for credential ${credentialIdBase64url}`);
|
||||
log(`verifyAuthentication: passkey not found for credential ${credentialIdBase64url}`);
|
||||
throw new BoxError(BoxError.NOT_FOUND, 'Passkey not found');
|
||||
}
|
||||
|
||||
if (passkey.userId !== user.id) {
|
||||
debug(`verifyAuthentication: passkey belongs to different user`);
|
||||
log(`verifyAuthentication: passkey belongs to different user`);
|
||||
throw new BoxError(BoxError.INVALID_CREDENTIALS, 'Passkey does not belong to this user');
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ async function verifyAuthentication(user, response) {
|
||||
}));
|
||||
|
||||
if (error) {
|
||||
debug(`verifyAuthentication: verification failed for user ${user.id}:`, error);
|
||||
log(`verifyAuthentication: verification failed for user ${user.id}:`, error);
|
||||
throw new BoxError(BoxError.INVALID_CREDENTIALS, 'Passkey verification failed');
|
||||
}
|
||||
|
||||
@@ -276,7 +276,7 @@ async function verifyAuthentication(user, response) {
|
||||
|
||||
await updateCounter(passkey.id, verification.authenticationInfo.newCounter);
|
||||
|
||||
debug(`verifyAuthentication: passkey verified for user ${user.id}`);
|
||||
log(`verifyAuthentication: passkey verified for user ${user.id}`);
|
||||
|
||||
return { verified: true, passkeyId: passkey.id };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user