From b1da9f514ab50dda1979539ce7b2eee41d7728e4 Mon Sep 17 00:00:00 2001 From: mk1020 Date: Sun, 13 Jun 2021 17:23:15 +0300 Subject: [PATCH] add env variable NODE_ENV, change confirm email link --- app/components/auth/signUp.ts | 4 ++-- app/envConfig.ts | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/components/auth/signUp.ts b/app/components/auth/signUp.ts index 97b7492..6028302 100644 --- a/app/components/auth/signUp.ts +++ b/app/components/auth/signUp.ts @@ -4,6 +4,7 @@ import {sha256} from './assistant'; import {createTransport} from 'nodemailer'; import {SMTPOpt} from '@/assist/mail'; import {randomBytes} from 'crypto'; +import {env} from '@/envConfig'; interface IBody { email: string @@ -23,14 +24,13 @@ export const signUp = async (server: FastifyInstance) => { if (rowCount) { const transporter = createTransport(SMTPOpt); - const link = 'http://localhost:3000/confirm-email/' + linkCode; + const link = `http://${env.nodeEnv === 'dev' ? 'localhost:3000' : '51.15.71.195'}/confirm-email/` + linkCode; const mailOptions = { to: email, subject: 'Confirmation of registration', html: `

Hello.

Please click on the link to confirm your registration.

` }; const sent = await transporter.sendMail(mailOptions); - console.log('sent', sent); if (sent) { return reply.status(201).send('An email has been sent to your email address'); } else { diff --git a/app/envConfig.ts b/app/envConfig.ts index e2bdece..f402aee 100644 --- a/app/envConfig.ts +++ b/app/envConfig.ts @@ -1,5 +1,6 @@ type TEnv = { + nodeEnv: string, port: string, passSalt: string, host: string, @@ -11,6 +12,7 @@ type TEnv = { } export const env:TEnv = { + nodeEnv: process.env.NODE_ENV as string, port: process.env.PORT as string, host: process.env.HOST as string, passSalt: process.env.PASS_SALT as string,