Skip to content

Commit

Permalink
refactor: change sus initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPdgn committed Dec 19, 2024
1 parent 51eb454 commit 909a2d1
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions modules/authentication/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,13 @@ export namespace AuthUtils {
);
}

export function checkResendThreshold(
token: Token,
notBefore: number = ConfigController.getInstance().config.local.verification
.resend_threshold,
) {
export function checkResendThreshold(token: Token, notBefore?: number) {
const threshold =
notBefore ||
ConfigController.getInstance().config.local.verification.resend_threshold;
const diffInMilliSec = Math.abs(new Date(token.createdAt).getTime() - Date.now());
if (diffInMilliSec < notBefore) {
const remainTimeInSec = Math.ceil((notBefore - diffInMilliSec) / 1000);
if (diffInMilliSec < threshold) {
const remainTimeInSec = Math.ceil((threshold - diffInMilliSec) / 1000);
throw new GrpcError(
status.RESOURCE_EXHAUSTED,
'Verification not sent. You have to wait ' +
Expand Down

0 comments on commit 909a2d1

Please sign in to comment.