mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 13:25:12 +00:00
feat(core): support one time password (#9798)
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user