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