Skip to content

Commit 25f9917

Browse files
committed
fix: check current user id
1 parent 1b16b09 commit 25f9917

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

libs/application-generic/src/usecases/get-novu-provider-credentials/get-novu-provider-credentials.usecase.ts

+3-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
Injectable,
55
NotFoundException,
66
} from '@nestjs/common';
7-
import { MemberRepository, UserEntity, UserRepository } from '@novu/dal';
7+
import { MemberRepository, UserRepository } from '@novu/dal';
88
import {
99
EmailProviderIdEnum,
1010
ICredentials,
@@ -32,19 +32,9 @@ export class GetNovuProviderCredentials {
3232
integration.providerId === SmsProviderIdEnum.Novu
3333
) {
3434
if (integration.providerId === EmailProviderIdEnum.Novu && integration.recipientEmail) {
35-
const members = await this.memberRepository.getOrganizationMembers(integration.organizationId);
35+
const user = await this.userRepository.findById(integration.userId);
3636

37-
const memberUserIds = members.map((member) => member._userId);
38-
const memberUsers: UserEntity[] = [];
39-
40-
for (const member of memberUserIds) {
41-
const user = await this.userRepository.findById(member);
42-
memberUsers.push(user);
43-
}
44-
45-
const memberEmails = memberUsers.map((user) => user.email).filter((email): email is string => !!email);
46-
47-
if (!memberEmails.includes(integration.recipientEmail)) {
37+
if (user?.email !== integration.recipientEmail) {
4838
throw new ForbiddenException(
4939
`Recipient email (${integration.recipientEmail}) does not belong to any member of the organization. Novu test provider can only be used to send emails to organization members. Connect your own email provider to send emails to other addresses.`,
5040
);

0 commit comments

Comments
 (0)