Skip to content

Commit

Permalink
add env variable NODE_ENV, change confirm email link
Browse files Browse the repository at this point in the history
  • Loading branch information
mk1020 committed Jun 13, 2021
1 parent 087e652 commit b1da9f5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/components/auth/signUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: `<h3>Hello.</h3> <p>Please click on the <a href=${link}><b>link</b></a> to confirm your registration.</p>`
};
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 {
Expand Down
2 changes: 2 additions & 0 deletions app/envConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

type TEnv = {
nodeEnv: string,
port: string,
passSalt: string,
host: string,
Expand All @@ -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,
Expand Down

0 comments on commit b1da9f5

Please sign in to comment.