feat(server/email verification): configurable timeout (#5061)
This commit is contained in:
@@ -31,6 +31,7 @@ import {
|
||||
} from '@/modules/core/services/users/emailVerification'
|
||||
import { commandFactory } from '@/modules/shared/command'
|
||||
import { withOperationLogging } from '@/observability/domain/businessLogging'
|
||||
import { emailVerificationTimeoutMinutes } from '@/modules/shared/helpers/envHelper'
|
||||
|
||||
const getUser = getUserFactory({ db })
|
||||
const requestNewEmailVerification = requestNewEmailVerificationFactory({
|
||||
@@ -144,7 +145,10 @@ export default {
|
||||
db,
|
||||
operationFactory: ({ db }) =>
|
||||
verifyUserEmailFactory({
|
||||
getPendingVerificationByEmail: getPendingVerificationByEmailFactory({ db }),
|
||||
getPendingVerificationByEmail: getPendingVerificationByEmailFactory({
|
||||
db,
|
||||
verificationTimeoutMinutes: emailVerificationTimeoutMinutes()
|
||||
}),
|
||||
markUserEmailAsVerified: markUserEmailAsVerifiedFactory({
|
||||
updateUserEmail: updateUserEmailFactory({ db })
|
||||
}),
|
||||
|
||||
@@ -90,7 +90,13 @@ export const deleteOldAndInsertNewVerificationFactory =
|
||||
}
|
||||
|
||||
export const getPendingVerificationByEmailFactory =
|
||||
({ db }: { db: Knex }): GetPendingVerificationByEmail =>
|
||||
({
|
||||
db,
|
||||
verificationTimeoutMinutes
|
||||
}: {
|
||||
db: Knex
|
||||
verificationTimeoutMinutes: number
|
||||
}): GetPendingVerificationByEmail =>
|
||||
async ({ email }) => {
|
||||
return await tables
|
||||
.emailVerifications(db)
|
||||
@@ -98,7 +104,7 @@ export const getPendingVerificationByEmailFactory =
|
||||
.where(
|
||||
EmailVerifications.col.createdAt,
|
||||
'>',
|
||||
dayjs().subtract(5, 'minutes').toISOString()
|
||||
dayjs().subtract(verificationTimeoutMinutes, 'minutes').toISOString()
|
||||
)
|
||||
.orderBy(EmailVerifications.col.createdAt, 'desc')
|
||||
.first()
|
||||
|
||||
@@ -512,3 +512,7 @@ export const getFileUploadUrlExpiryMinutes = (): number => {
|
||||
export const getPreviewServiceTimeoutMilliseconds = (): number => {
|
||||
return getIntFromEnv('PREVIEW_SERVICE_TIMEOUT_MILLISECONDS', '3600000') // 1 hour
|
||||
}
|
||||
|
||||
export const emailVerificationTimeoutMinutes = (): number => {
|
||||
return getIntFromEnv('EMAIL_VERIFICATION_TIMEOUT_MINUTES', '5')
|
||||
}
|
||||
|
||||
@@ -967,6 +967,8 @@ Generate the environment variables for Speckle server and Speckle objects deploy
|
||||
key: {{ default "email_password" .Values.server.email.password.secretKey }}
|
||||
- name: EMAIL_FROM
|
||||
value: "{{ .Values.server.email.from }}"
|
||||
- name: EMAIL_VERIFICATION_TIMEOUT_MINUTES
|
||||
value: {{ .Values.server.email.verificationTimeoutMinutes | quote }}
|
||||
{{- end }}
|
||||
|
||||
# *** Newsletter ***
|
||||
|
||||
@@ -1282,6 +1282,11 @@
|
||||
"description": "If enabled, Speckle can send email to users - for example, email verification for account registration.",
|
||||
"default": false
|
||||
},
|
||||
"verificationTimeoutMinutes": {
|
||||
"type": "number",
|
||||
"description": "The number of minutes after which an email verification link will expire. Defaults to 5 minutes.",
|
||||
"default": 5
|
||||
},
|
||||
"host": {
|
||||
"type": "string",
|
||||
"description": "The domain name or IP address of the server hosting the email service.",
|
||||
|
||||
@@ -778,6 +778,9 @@ server:
|
||||
## @param server.email.enabled If enabled, Speckle can send email to users - for example, email verification for account registration.
|
||||
##
|
||||
enabled: false
|
||||
## @param server.email.verificationTimeoutMinutes The number of minutes after which an email verification link will expire. Defaults to 5 minutes.
|
||||
##
|
||||
verificationTimeoutMinutes: 5
|
||||
## @param server.email.host The domain name or IP address of the server hosting the email service.
|
||||
##
|
||||
host: ''
|
||||
|
||||
Reference in New Issue
Block a user