Skip to content

Commit

Permalink
feat: make resend verification threshold configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPdgn committed Dec 19, 2024
1 parent 1294bb5 commit 51eb454
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions modules/authentication/src/config/local.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export default {
format: 'String',
default: '',
},
resend_threshold: {
doc: 'Defines the threshold in milliseconds for resending verification',
format: 'Number',
default: 60000,
},
},
forgot_password_redirect_uri: {
doc: 'Defines where the user should be redirected once they click the forgot password link',
Expand Down
14 changes: 9 additions & 5 deletions modules/authentication/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,19 @@ export namespace AuthUtils {
);
}

export function checkResendThreshold(token: Token, notBefore: number = 600000) {
export function checkResendThreshold(
token: Token,
notBefore: number = ConfigController.getInstance().config.local.verification
.resend_threshold,
) {
const diffInMilliSec = Math.abs(new Date(token.createdAt).getTime() - Date.now());
if (diffInMilliSec < notBefore) {
const remainTime = Math.ceil((notBefore - diffInMilliSec) / notBefore);
const remainTimeInSec = Math.ceil((notBefore - diffInMilliSec) / 1000);
throw new GrpcError(
status.RESOURCE_EXHAUSTED,
'Verification code not sent. You have to wait ' +
remainTime +
' minutes to try again',
'Verification not sent. You have to wait ' +
remainTimeInSec +
' seconds to try again',
);
} else {
return true;
Expand Down

0 comments on commit 51eb454

Please sign in to comment.