eletrotupi / tcc/ api/src/services/mail/sendPasswordReset.ts11f22a75d9fc5f839720f7c0fada4359dcf1b9b5
776 B | 31 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
  const { data, error } = await sendEmail({
20
    to: user!.email,
21
    subject: "Esqueceu a senha do nexo?",
22
    text: email(user!.firstName, token)
23
  });
24

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

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