fix: send email if username is being passed (#6674)

Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>

Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
pull/6691/head
Udit Takkar 2023-01-25 14:26:20 +05:30 committed by GitHub
parent 00bff598ef
commit 5b1cd9e5ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -27,6 +27,7 @@ import { TRPCError } from "@trpc/server";
import { authedProcedure, router } from "../../trpc";
const isEmail = (str: string) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(str);
export const viewerTeamsRouter = router({
// Retrieves team by id
get: authedProcedure
@ -282,7 +283,6 @@ export const viewerTeamsRouter = router({
if (!invitee) {
// liberal email match
const isEmail = (str: string) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(str);
if (!isEmail(input.usernameOrEmail))
throw new TRPCError({
@ -345,12 +345,16 @@ export const viewerTeamsRouter = router({
} else throw e;
}
let sendTo = input.usernameOrEmail;
if (!isEmail(input.usernameOrEmail)) {
sendTo = invitee.email;
}
// inform user of membership by email
if (input.sendEmailInvitation && ctx?.user?.name && team?.name) {
await sendTeamInviteEmail({
language: translation,
from: ctx.user.name,
to: input.usernameOrEmail,
to: sendTo,
teamName: team.name,
joinLink: WEBAPP_URL + "/settings/teams",
});