fix: smtp and appEnv
This commit is contained in:
parent
d0808a54c4
commit
a4000047d6
|
|
@ -1,7 +1,14 @@
|
|||
BASE_URL =
|
||||
APP_PORT = 3000
|
||||
|
||||
DATABASE_URL =
|
||||
|
||||
ACCESS_TOKEN_SECRET =
|
||||
REFRESH_TOKEN_SECRET =
|
||||
COOKIE_SECRET =
|
||||
RESET_PASSWORD_TOKEN_SECRET =
|
||||
COOKIE_SECRET =
|
||||
|
||||
SMTP_USERNAME =
|
||||
SMTP_PASSWORD =
|
||||
SMTP_HOST =
|
||||
SMTP_PORT =
|
||||
|
|
@ -4,12 +4,17 @@ import { z } from "zod";
|
|||
dotenv.config();
|
||||
|
||||
const envSchema = z.object({
|
||||
BASE_URL: z.string(),
|
||||
APP_PORT: z.coerce.number().int(),
|
||||
DATABASE_URL: z.string(),
|
||||
ACCESS_TOKEN_SECRET: z.string(),
|
||||
REFRESH_TOKEN_SECRET: z.string(),
|
||||
RESET_PASSWORD_TOKEN_SECRET: z.string(),
|
||||
COOKIE_SECRET: z.string(),
|
||||
SMTP_USERNAME: z.string(),
|
||||
SMTP_PASSWORD: z.string(),
|
||||
SMTP_HOST: z.string(),
|
||||
SMTP_PORT: z.coerce.number().int(),
|
||||
});
|
||||
|
||||
const parsedEnv = envSchema.safeParse(process.env);
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
import nodemailer from 'nodemailer';
|
||||
import appEnv from '../appEnv';
|
||||
|
||||
/**
|
||||
* Nodemailer configuration
|
||||
*/
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: 'smtp.gmail.com',
|
||||
port: 587,
|
||||
host: appEnv.SMTP_HOST,
|
||||
port: appEnv.SMTP_PORT,
|
||||
secure: false,
|
||||
auth: {
|
||||
user: process.env.EMAIL_USER,
|
||||
pass: process.env.EMAIL_PASS,
|
||||
user: appEnv.SMTP_USERNAME,
|
||||
pass: appEnv.SMTP_PASSWORD,
|
||||
},
|
||||
tls: {
|
||||
rejectUnauthorized: false,
|
||||
|
|
@ -17,10 +18,10 @@ const transporter = nodemailer.createTransport({
|
|||
});
|
||||
|
||||
export async function sendResetPasswordEmail(to: string, token: string) {
|
||||
const resetUrl = `https://localhost:3000/forgot-password/verify?token=${token}`;
|
||||
const resetUrl = appEnv.BASE_URL + '/forgot-password/verify?token=' + token;
|
||||
|
||||
const info = await transporter.sendMail({
|
||||
from: '"Your App" <${process.env.EMAIL_USER}>',
|
||||
from: `"Your App" <${appEnv.SMTP_USERNAME}>`,
|
||||
to,
|
||||
subject: 'Password Reset Request',
|
||||
text: `You requested a password reset. Click this link to reset your password: ${resetUrl}`,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user