diff --git a/backend/src/ee/services/saml-config/saml-config-service.ts b/backend/src/ee/services/saml-config/saml-config-service.ts index 270462165..df945d950 100644 --- a/backend/src/ee/services/saml-config/saml-config-service.ts +++ b/backend/src/ee/services/saml-config/saml-config-service.ts @@ -423,6 +423,7 @@ export const samlConfigServiceFactory = ({ organizationSlug: organization.slug, authMethod: authProvider, hasExchangedPrivateKey: true, + aliasId: userAlias.id, authType: UserAliasType.SAML, isUserCompleted, ...(relayState diff --git a/backend/src/server/routes/v2/user-router.ts b/backend/src/server/routes/v2/user-router.ts index f4b02e7be..f7c0a11d3 100644 --- a/backend/src/server/routes/v2/user-router.ts +++ b/backend/src/server/routes/v2/user-router.ts @@ -20,15 +20,12 @@ export const registerUserRouter = async (server: FastifyZodProvider) => { headers: z.object({ referer: z.string().trim() }), - body: z.object({ - username: z.string().trim() - }), response: { 200: z.object({}) } }, handler: async (req) => { - await server.services.user.sendEmailVerificationCode(req.body.username, req.headers.referer); + await server.services.user.sendEmailVerificationCode(req.headers.referer); return {}; } }); diff --git a/backend/src/services/user/user-service.ts b/backend/src/services/user/user-service.ts index 55c9de185..6b450db62 100644 --- a/backend/src/services/user/user-service.ts +++ b/backend/src/services/user/user-service.ts @@ -54,18 +54,22 @@ export const userServiceFactory = ({ permissionService, userAliasDAL }: TUserServiceFactoryDep) => { - const sendEmailVerificationCode = async (username: string, referer: string) => { + const sendEmailVerificationCode = async (referer: string) => { + const url = new URL(referer); + const refererToken = url.searchParams.get("token"); + if (!refererToken) + throw new BadRequestError({ name: "Failed to send email verification code due to no token on referer" }); + const { authType, aliasId, username } = crypto.jwt().decode(refererToken) as { + authType: string; + aliasId: string; + username: string; + }; // akhilmhdh: case sensitive email resolution const users = await userDAL.findUserByUsername(username); const user = users?.length > 1 ? users.find((el) => el.username === username) : users?.[0]; if (!user) throw new NotFoundError({ name: `User with username '${username}' not found` }); let { isEmailVerified } = user; - const url = new URL(referer); - const refererToken = url.searchParams.get("token"); - if (!refererToken) - throw new BadRequestError({ name: "Failed to send email verification code due to no token on referer" }); - const { authType } = crypto.jwt().decode(refererToken) as { authType: string }; - const userAlias = await userAliasDAL.findOne({ userId: user.id, aliasType: authType }); + const userAlias = await userAliasDAL.findOne({ userId: user.id, aliasType: authType, id: aliasId }); if (userAlias) { isEmailVerified = userAlias.isEmailVerified; }