Skip to content

Commit

Permalink
feat: add front-end url as an env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
HJassar committed Oct 17, 2022
1 parent dad0e99 commit 9dd8932
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions .env.example
Expand Up @@ -23,6 +23,7 @@ SMTP_PORT=587
SMTP_USERNAME=email-server-username
SMTP_PASSWORD=email-server-password
EMAIL_FROM=support@yourapp.com
FRONT_URL=http://localhost:5000

# Cookie configs
COOKIE_SECRET=thisisasamplesecret
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -203,6 +203,7 @@ SMTP_PORT=587
SMTP_USERNAME=email-server-username
SMTP_PASSWORD=email-server-password
EMAIL_FROM=support@yourapp.com
FRONT_URL=http://localhost:5000
```

## Project Structure
Expand Down
2 changes: 2 additions & 0 deletions src/config/config.ts
Expand Up @@ -20,6 +20,7 @@ const envVarsSchema = Joi.object()
SMTP_USERNAME: Joi.string().description('username for email server'),
SMTP_PASSWORD: Joi.string().description('password for email server'),
EMAIL_FROM: Joi.string().description('the from field in the emails sent by the app'),
FRONT_URL: Joi.string().required().description('Front url'),
})
.unknown();

Expand Down Expand Up @@ -63,6 +64,7 @@ const config = {
},
from: envVars.EMAIL_FROM,
},
frontUrl: envVars.FRONT_URL,
};

export default config;
8 changes: 4 additions & 4 deletions src/modules/email/email.service.ts
Expand Up @@ -40,7 +40,7 @@ export const sendEmail = async (to: string, subject: string, text: string, html:
export const sendResetPasswordEmail = async (to: string, token: string): Promise<void> => {
const subject = 'Reset password';
// replace this url with the link to the reset password page of your front-end app
const resetPasswordUrl = `http://link-to-app/reset-password?token=${token}`;
const resetPasswordUrl = `http://${config.frontUrl}/reset-password?token=${token}`;
const text = `Hi,
To reset your password, click on this link: ${resetPasswordUrl}
If you did not request any password resets, then ignore this email.`;
Expand All @@ -62,7 +62,7 @@ export const sendResetPasswordEmail = async (to: string, token: string): Promise
export const sendVerificationEmail = async (to: string, token: string, name: string): Promise<void> => {
const subject = 'Email Verification';
// replace this url with the link to the email verification page of your front-end app
const verificationEmailUrl = `http://link-to-app/verify-email?token=${token}`;
const verificationEmailUrl = `http://${config.frontUrl}/verify-email?token=${token}`;
const text = `Hi ${name},
To verify your email, click on this link: ${verificationEmailUrl}
If you did not create an account, then ignore this email.`;
Expand All @@ -82,7 +82,7 @@ export const sendVerificationEmail = async (to: string, token: string, name: str
export const sendSuccessfulRegistration = async (to: string, token: string, name: string): Promise<void> => {
const subject = 'Email Verification';
// replace this url with the link to the email verification page of your front-end app
const verificationEmailUrl = `http://link-to-app/verify-email?token=${token}`;
const verificationEmailUrl = `http://${config.frontUrl}/verify-email?token=${token}`;
const text = `Hi ${name},
Congratulations! Your account has been created.
You are almost there. Complete the final step by verifying your email at: ${verificationEmailUrl}
Expand All @@ -107,7 +107,7 @@ export const sendSuccessfulRegistration = async (to: string, token: string, name
export const sendAccountCreated = async (to: string, name: string): Promise<void> => {
const subject = 'Account Created Successfully';
// replace this url with the link to the email verification page of your front-end app
const loginUrl = 'http://link-to-app/auth/login';
const loginUrl = `http://${config.frontUrl}/auth/login`;
const text = `Hi ${name},
Congratulations! Your account has been created successfully.
You can now login at: ${loginUrl}
Expand Down

0 comments on commit 9dd8932

Please sign in to comment.