QFIX: Fix missing SES_AUTH_TOKEN (#8026)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev
2025-02-17 17:51:40 +07:00
committed by GitHub
parent b3014383ed
commit b487cb949b
4 changed files with 21 additions and 8 deletions
+4
View File
@@ -64,6 +64,8 @@ export function serveAccount (measureCtx: MeasureContext, brandings: BrandingMap
})
const ses = process.env.SES_URL
const sesAuthToken = process.env.SES_AUTH_TOKEN
const frontURL = process.env.FRONT_URL
const productName = process.env.PRODUCT_NAME
const lang = process.env.LANGUAGE ?? 'en'
@@ -85,6 +87,8 @@ export function serveAccount (measureCtx: MeasureContext, brandings: BrandingMap
setMetadata(account.metadata.OtpTimeToLiveSec, parseInt(process.env.OTP_TIME_TO_LIVE ?? '60'))
setMetadata(account.metadata.OtpRetryDelaySec, parseInt(process.env.OTP_RETRY_DELAY ?? '60'))
setMetadata(account.metadata.SES_URL, ses)
setMetadata(account.metadata.SES_AUTH_TOKEN, sesAuthToken)
setMetadata(account.metadata.FrontURL, frontURL)
setMetadata(account.metadata.WsLivenessDays, wsLivenessDays)
+6 -4
View File
@@ -371,7 +371,7 @@ export async function sendInvite (
throw new PlatformError(new Status(Severity.ERROR, platform.status.WorkspaceNotFound, { workspaceUuid }))
}
const sesURL = getSesUrl()
const { sesURL, sesAuth } = getSesUrl()
const front = getFrontUrl(branding)
const expHours = 48
const exp = expHours * 60 * 60 * 1000
@@ -389,7 +389,8 @@ export async function sendInvite (
await fetch(concatLink(sesURL, '/send'), {
method: 'post',
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
...(sesAuth != null ? { Authorization: `Bearer ${sesAuth}` } : {})
},
body: JSON.stringify({
text,
@@ -599,7 +600,7 @@ export async function requestPasswordReset (
)
}
const sesURL = getSesUrl()
const { sesURL, sesAuth } = getSesUrl()
const front = getFrontUrl(branding)
const token = generateToken(account.uuid, undefined, {
@@ -615,7 +616,8 @@ export async function requestPasswordReset (
await fetch(concatLink(sesURL, '/send'), {
method: 'post',
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
...(sesAuth != null ? { Authorization: `Bearer ${sesAuth}` } : {})
},
body: JSON.stringify({
text,
+1
View File
@@ -12,6 +12,7 @@ export const accountPlugin = plugin(accountId, {
metadata: {
FrontURL: '' as Metadata<string>,
SES_URL: '' as Metadata<string>,
SES_AUTH_TOKEN: '' as Metadata<string>,
ProductName: '' as Metadata<string>,
Transactors: '' as Metadata<string>,
OtpTimeToLiveSec: '' as Metadata<number>,
+10 -4
View File
@@ -378,6 +378,7 @@ export async function sendOtpEmail (
ctx.error('Please provide email service url to enable email otp')
return
}
const sesAuth = getMetadata(accountPlugin.metadata.SES_AUTH_TOKEN)
const lang = branding?.language
const app = branding?.title ?? getMetadata(accountPlugin.metadata.ProductName)
@@ -390,7 +391,8 @@ export async function sendOtpEmail (
await fetch(concatLink(sesURL, '/send'), {
method: 'POST',
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
...(sesAuth != null ? { Authorization: `Bearer ${sesAuth}` } : {})
},
body: JSON.stringify({
text,
@@ -735,6 +737,8 @@ export async function sendEmailConfirmation (
throw new PlatformError(new Status(Severity.ERROR, platform.status.InternalServerError, {}))
}
const sesAuth = getMetadata(accountPlugin.metadata.SES_AUTH_TOKEN)
const front = branding?.front ?? getMetadata(accountPlugin.metadata.FrontURL)
if (front === undefined || front === '') {
ctx.error('Please provide front url via branding configuration or FRONT_URL variable')
@@ -756,7 +760,8 @@ export async function sendEmailConfirmation (
await fetch(concatLink(sesURL, '/send'), {
method: 'post',
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
...(sesAuth != null ? { Authorization: `Bearer ${sesAuth}` } : {})
},
body: JSON.stringify({
text,
@@ -863,14 +868,15 @@ export async function getEmailSocialId (db: AccountDB, email: string): Promise<S
return await db.socialId.findOne({ type: SocialIdType.EMAIL, value: email })
}
export function getSesUrl (): string {
export function getSesUrl (): { sesURL: string, sesAuth: string | undefined } {
const sesURL = getMetadata(accountPlugin.metadata.SES_URL)
if (sesURL === undefined || sesURL === '') {
throw new Error('Please provide email service url')
}
const sesAuth = getMetadata(accountPlugin.metadata.SES_AUTH_TOKEN)
return sesURL
return { sesURL, sesAuth }
}
export function getFrontUrl (branding: Branding | null): string {