From d7b974b106f0933e8deb284818770d58770e1985 Mon Sep 17 00:00:00 2001
From: Alexander Onnikov <Alexander.Onnikov@xored.com>
Date: Fri, 9 Aug 2024 00:12:14 +0700
Subject: [PATCH] fix: does not send email confirmation when signup with otp
 (#6292)

Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
---
 server/account/src/operations.ts | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/server/account/src/operations.ts b/server/account/src/operations.ts
index a2c621bbef..2adea7cb3a 100644
--- a/server/account/src/operations.ts
+++ b/server/account/src/operations.ts
@@ -898,6 +898,7 @@ export async function createAcc (
   first: string,
   last: string,
   confirmed: boolean = false,
+  shouldConfirm: boolean = true,
   extra?: Record<string, string>
 ): Promise<Account> {
   const email = cleanEmail(_email)
@@ -933,7 +934,7 @@ export async function createAcc (
     throw new PlatformError(new Status(Severity.ERROR, platform.status.AccountAlreadyExists, { account: email }))
   }
   const sesURL = getMetadata(accountPlugin.metadata.SES_URL)
-  if (!confirmed) {
+  if (!confirmed && shouldConfirm) {
     if (sesURL !== undefined && sesURL !== '') {
       await sendConfirmation(productId, branding, newAccount)
     } else {
@@ -994,7 +995,7 @@ export async function signUpOtp (
   const first = email.split('@', 1)[0] ?? ''
   const last = ''
 
-  await createAcc(ctx, db, productId, branding, email, null, first, last, false)
+  await createAcc(ctx, db, productId, branding, email, null, first, last, false, false)
 
   return await sendOtp(ctx, db, productId, branding, _email)
 }
@@ -2525,7 +2526,7 @@ export async function joinWithProvider (
       await useInvite(db, inviteId)
       return result
     }
-    const newAccount = await createAcc(ctx, db, productId, branding, email, null, first, last, true, extra)
+    const newAccount = await createAcc(ctx, db, productId, branding, email, null, first, last, true, true, extra)
     const token = generateToken(email, getWorkspaceId('', productId), getExtra(newAccount))
     const ws = await assignWorkspace(
       ctx,
@@ -2589,7 +2590,7 @@ export async function loginWithProvider (
       }
       return result
     }
-    const newAccount = await createAcc(ctx, db, productId, branding, email, null, first, last, true, extra)
+    const newAccount = await createAcc(ctx, db, productId, branding, email, null, first, last, true, true, extra)
 
     const result = {
       endpoint: '',