diff --git a/modules/authentication/src/config/local.config.ts b/modules/authentication/src/config/local.config.ts index 653f91387..caa1ae0eb 100644 --- a/modules/authentication/src/config/local.config.ts +++ b/modules/authentication/src/config/local.config.ts @@ -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', diff --git a/modules/authentication/src/utils/index.ts b/modules/authentication/src/utils/index.ts index 259421f84..98b281753 100644 --- a/modules/authentication/src/utils/index.ts +++ b/modules/authentication/src/utils/index.ts @@ -122,15 +122,18 @@ export namespace AuthUtils { ); } - export function checkResendThreshold(token: Token, notBefore: number = 600000) { + 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 remainTime = Math.ceil((notBefore - diffInMilliSec) / notBefore); + if (diffInMilliSec < threshold) { + const remainTimeInSec = Math.ceil((threshold - 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;