feat(core): support one time password (#9798)

This commit is contained in:
forehalo
2025-01-22 07:33:09 +00:00
parent bf797c7a0c
commit 5828eb53b6
16 changed files with 362 additions and 131 deletions

View File

@@ -136,8 +136,12 @@ export class UserFriendlyError extends Error {
return;
}
new Logger(context).error(
'Internal server error',
const logger = new Logger(context);
const fn = this.status >= 500 ? logger.error : logger.log;
fn.call(
logger,
this.name,
this.cause ? ((this.cause as any).stack ?? this.cause) : this.stack
);
}

View File

@@ -5,6 +5,7 @@ import {
createSign,
createVerify,
randomBytes,
randomInt,
timingSafeEqual,
} from 'node:crypto';
@@ -109,6 +110,20 @@ export class CryptoHelper {
return randomBytes(length);
}
randomInt(min: number, max: number) {
return randomInt(min, max);
}
otp(length = 6) {
let otp = '';
for (let i = 0; i < length; i++) {
otp += this.randomInt(0, 9).toString();
}
return otp;
}
sha256(data: string) {
return createHash('sha256').update(data).digest();
}