fix: re-invite member procedure

This commit is contained in:
Sushant kumar
2024-05-17 05:59:51 +05:30
parent 44b8e86793
commit e49eaac937
@@ -1,4 +1,5 @@
import { sendMemberInviteEmail } from "@/jobs/member-inivite-email";
import { generatePasswordResetToken } from "@/lib/token";
import { Audit } from "@/server/audit";
import { checkMembership } from "@/server/auth";
import {
@@ -16,11 +17,10 @@ export const reInviteProcedure = withAuth
const user = session.user;
const trigger = getTriggerClient();
const { authTokenHash, expires, memberInviteTokenHash, token } =
await generateInviteToken();
const { expires, memberInviteTokenHash } = await generateInviteToken();
const { company, verificationToken, email } = await db.$transaction(
async (tx) => {
const { company, verificationToken, email, passwordResetToken } =
await db.$transaction(async (tx) => {
const { companyId } = await checkMembership({ session, tx });
const company = await tx.company.findFirstOrThrow({
@@ -74,15 +74,6 @@ export const reInviteProcedure = withAuth
},
});
// next-auth verification token
await tx.verificationToken.create({
data: {
identifier: email,
token: authTokenHash,
expires,
},
});
await Audit.create(
{
action: "member.re-invited",
@@ -98,13 +89,15 @@ export const reInviteProcedure = withAuth
tx,
);
return { verificationToken, company, email };
},
);
const { token: passwordResetToken } =
await generatePasswordResetToken(email);
return { verificationToken, company, email, passwordResetToken };
});
const payload = {
verificationToken,
token,
passwordResetToken,
email,
company,
user: {