eletrotupi / tcc/ api/src/services/mail/sendPasswordReset.ts0c53ce12780375681fbfe522a63114d3a835f630
821 B | 33 lines Raw
1
import { findUserById } from '@app/services/user.service';
2
import { sendEmail }  from '@app/lib/mail';
3

4
const email = (firstName: string, token: string) => {
5
  return (`
6
Oi, ${firstName}.
7

8
Ouvimos por aí que você precisa trocar a senha?
9

10
Segue o código para você digitar no app: ${token}
11

12
Qualquer coisa prende o grito!
13
`)
14
}
15

16
export async function sendResetPasswordEmail(userId: number, token: string): Promise<void> {
17
  const user = await findUserById(userId)!;
18

19
  console.log("Email/passwdReset: ", user);
20

21
  const { data, error } = await sendEmail({
22
    to: user!.email,
23
    subject: "Esqueceu a senha do nexo?",
24
    text: email(user!.firstName, token)
25
  });
26

27
  if (error) {
28
    console.error("Error sending email: ", error);
29
  }
30

31
  console.log("Email sent successfully!");
32
  console.log("Email ID:", data?.id);
33
}