Skip to content

Commit

Permalink
fix: apply suggestions by coderabbitai
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-rocket committed Jan 24, 2025
1 parent 601e6e1 commit ba8db69
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/core/src/lib/invite/invite.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export class InviteService extends TenantAwareCrudService<Invite> {
})
);
} else {
ignoreInvites++;
ignoreInvites;
}
} else {
invites.push(
Expand Down Expand Up @@ -336,6 +336,22 @@ export class InviteService extends TenantAwareCrudService<Invite> {
.join('&');
}

/**
* Generates an invite code and a secure JWT token for email-based invites.
*
* @param {string} email - The email address for which the invite code and token are generated.
* @returns {{ code: string; token: string }} - An object containing the invite code and JWT token.
*/
private generateInviteCodeAndToken(email: string): { code: string; token: string } {
// Generate a unique invite code
const code = generateAlphaNumericCode();

// Generate a JWT token containing the email and invite code
const token = sign({ email, code }, environment.JWT_SECRET, {});

return { code, token };
}

async resendEmail(input: IInviteResendInput, languageCode: LanguagesEnum) {
const originUrl = this.configService.get('clientBaseUrl') as string;
const { inviteId, inviteType, callbackUrl } = input;
Expand Down Expand Up @@ -363,8 +379,7 @@ export class InviteService extends TenantAwareCrudService<Invite> {
*/
const invitedBy: IUser = await this.userService.findOneByIdString(RequestContext.currentUserId());
try {
const code = generateAlphaNumericCode();
const token: string = sign({ email, code }, environment.JWT_SECRET, {});
const { code, token } = this.generateInviteCodeAndToken(email);

const registerUrl = `${originUrl}/#/auth/accept-invite?email=${encodeURIComponent(email)}&token=${token}`;
if (inviteType === InvitationTypeEnum.USER) {
Expand Down

0 comments on commit ba8db69

Please sign in to comment.