feat: update Invito email template to include invite URL and remove sensitive user information

This commit is contained in:
Marco Pedone 2026-03-27 19:18:54 +01:00
parent 67958105a1
commit 4eabd56a83
3 changed files with 27 additions and 23 deletions

View file

@ -1,5 +1,4 @@
import { Button, Heading, Row, Section, Text } from "@react-email/components"; import { Button, Heading, Row, Section, Text } from "@react-email/components";
import { env } from "~/env";
import Base from "./base"; import Base from "./base";
export type Invito_NewMail = { export type Invito_NewMail = {
mailType: "invito"; mailType: "invito";
@ -8,16 +7,16 @@ export type Invito_NewMail = {
type InvitoProps = { type InvitoProps = {
nome: string; nome: string;
email: string; //email: string;
password: string; //password: string;
//inviteUrl: string; inviteUrl: string;
}; };
const Invito = ({ const Invito = ({
nome, nome,
//inviteUrl, inviteUrl,
email, //email,
password //password
}: InvitoProps) => { }: InvitoProps) => {
return ( return (
<Base preview="Procedi ora su Infoalloggi.it"> <Base preview="Procedi ora su Infoalloggi.it">
@ -34,7 +33,7 @@ const Invito = ({
disponibili. disponibili.
</Text> </Text>
</Row> </Row>
<Row> {/* <Row>
<Text> <Text>
Le tue credenziali sono: Le tue credenziali sono:
<br /> <br />
@ -42,13 +41,13 @@ const Invito = ({
<br /> <br />
Password: <b>{password}</b> Password: <b>{password}</b>
</Text> </Text>
</Row> </Row> */}
<Section className="mb-5"> <Section className="mb-5">
<Button <Button
className="mx-auto box-border inline-flex h-10 items-center justify-center whitespace-nowrap rounded-md bg-sky-500 px-4 py-2 text-center align-middle font-semibold text-white" className="mx-auto box-border inline-flex h-10 items-center justify-center whitespace-nowrap rounded-md bg-sky-500 px-4 py-2 text-center align-middle font-semibold text-white"
//href={inviteUrl} href={inviteUrl}
href={`${env.BASE_URL}/area-riservata/dashboard`} //href={`${env.BASE_URL}/area-riservata/dashboard`}
> >
Clicca qui per procedere Clicca qui per procedere
</Button> </Button>

View file

@ -1,12 +1,15 @@
import { TRPCError } from "@trpc/server"; import { TRPCError } from "@trpc/server";
import { z } from "zod"; import { z } from "zod";
import { env } from "~/env";
import { import {
adminProcedure, adminProcedure,
createTRPCRouter, createTRPCRouter,
publicProcedure, publicProcedure,
} from "~/server/api/trpc"; } from "~/server/api/trpc";
import { swapAuth } from "~/server/controllers/auth.controller";
import { import {
consumeInviteToken, consumeInviteToken,
createInviteToken,
sendInvitoEmail, sendInvitoEmail,
verifyInviteToken, verifyInviteToken,
} from "~/server/controllers/invites.controller"; } from "~/server/controllers/invites.controller";
@ -27,16 +30,17 @@ export const inviteRouter = createTRPCRouter({
.mutation(async ({ input }) => { .mutation(async ({ input }) => {
try { try {
const user = await getUser({ userId: input.id, db }); const user = await getUser({ userId: input.id, db });
//const token = await createInviteToken(user.email);
//const inviteUrl = `${env.BASE_URL}/auth/accetta-invito/${token}`; const token = await createInviteToken(user.email);
const inviteUrl = `${env.BASE_URL}/auth/accetta-invito/${token}`;
await sendInvitoEmail({ await sendInvitoEmail({
userId: input.id, userId: input.id,
email: user.email, email: user.email,
nome: user.nome, nome: user.nome,
password: user.password, //password: user.password,
//inviteUrl, inviteUrl,
}); });
return { success: true }; return { success: true };
@ -73,7 +77,7 @@ export const inviteRouter = createTRPCRouter({
password: z.string().min(8), password: z.string().min(8),
}), }),
) )
.mutation(async ({ input }) => { .mutation(async ({ input, ctx }) => {
const user = await findUser_byEmail({ email: input.email }); const user = await findUser_byEmail({ email: input.email });
if (!user) { if (!user) {
throw new TRPCError({ throw new TRPCError({
@ -104,6 +108,7 @@ export const inviteRouter = createTRPCRouter({
// Mark invite as used // Mark invite as used
await consumeInviteToken(input.token); await consumeInviteToken(input.token);
await swapAuth({ ctx, userId: user.id });
return { success: true }; return { success: true };
}), }),

View file

@ -67,25 +67,25 @@ export async function consumeInviteToken(token: string) {
export const sendInvitoEmail = async ({ export const sendInvitoEmail = async ({
userId, userId,
email, email,
password, //password,
nome, nome,
//inviteUrl, inviteUrl,
}: { }: {
userId: UsersId; userId: UsersId;
email: string; email: string;
password: string; //password: string;
nome: string; nome: string;
//inviteUrl: string; inviteUrl: string;
}) => { }) => {
try { try {
await NewMail({ await NewMail({
template: { template: {
mailType: "invito", mailType: "invito",
props: { props: {
email, //email,
nome, nome,
password, //password,
//inviteUrl, inviteUrl,
}, },
}, },
mail: { mail: {