diff --git a/server/README.md b/server/README.md index 5309b29..fcffcec 100644 --- a/server/README.md +++ b/server/README.md @@ -25,6 +25,8 @@ _*For quick start, copy the `template.env` file to `.env`. The values given in ` | MAILER_SENDER_EMAIL | Email address for sending emails | | MAILER_SENDER_PASS | Password for authenticating with SMTP Host | | MAILER_HOST | SMTP Host supporting TLS which will send our emails | +| DEBUG | Enable debugging mode - disables some features and enables debugging features (dev only) | +| ENABLE_EMAIL_NOTIFICATIONS | Set this flag to enable emails to be sent, if set to false emails will not be sent,default true| ### Cors and Cookies diff --git a/server/src/auth/auth.service.ts b/server/src/auth/auth.service.ts index 7b5e6e9..6c7f72e 100644 --- a/server/src/auth/auth.service.ts +++ b/server/src/auth/auth.service.ts @@ -8,6 +8,7 @@ import { RegisterResponseDto } from './dto/register-response.dto'; import { saltRounds } from './constants'; import { SignInResponseDto } from './dto/sign-in-response.dto'; import { MailerService } from 'src/mailer/mailer.service'; +import { appConfig } from 'src/config'; @Injectable() export class AuthService { @@ -15,7 +16,7 @@ export class AuthService { private usersService: UsersService, private jwtService: JwtService, private mailer: MailerService, - ) {} + ) { } async login(email: string, password: string): Promise { const user = await this.usersService.findOneByEmail(email); @@ -28,12 +29,16 @@ export class AuthService { throw new UnauthorizedException(); } - await this.mailer.sendTemplateMail({ - templateType: 'login', - recipients: [email], - subject: 'Flux@Codegasms New Login Detected', - username: user.fullName, - }); + if (appConfig.enableMail) { + await this.mailer.sendTemplateMail({ + templateType: 'login', + recipients: [email], + subject: 'Flux@Codegasms New Login Detected', + username: user.fullName, + }); + } else { + console.log(`Simulating sending login mail to ${email}!`) + } return { access_token: await this.generateJwtToken(email), @@ -48,12 +53,16 @@ export class AuthService { hashedPassword: hashedPassword, }); - await this.mailer.sendTemplateMail({ - templateType: 'register', - recipients: [user.email], - subject: 'Welcome to Flux@Codegasms', - username: user.fullName, - }); + if (appConfig.enableMail) { + await this.mailer.sendTemplateMail({ + templateType: 'register', + recipients: [user.email], + subject: 'Welcome to Flux@Codegasms', + username: user.fullName, + }); + } else { + console.log(`Simulating sending registration mail to ${user.email}!`) + } return { access_token: await this.generateJwtToken(user.email), diff --git a/server/src/config.ts b/server/src/config.ts index 8f77129..a14c0ee 100644 --- a/server/src/config.ts +++ b/server/src/config.ts @@ -24,6 +24,7 @@ export const appConfig = { }, debug: fromEnv('DEBUG', 'false').toLowerCase() === 'true', + enableMail: fromEnv('ENABLE_EMAIL_NOTIFICATIONS', 'true').toLowerCase() === 'true', }; console.log(appConfig); diff --git a/server/template.env b/server/template.env index 7784c82..0d11664 100644 --- a/server/template.env +++ b/server/template.env @@ -15,4 +15,10 @@ CORS_ALLOWED_ORIGINS=http://localhost:5501/,http://localhost:8000/,http://127.0. MAILER_SENDER_EMAIL=noreply@codegasms.com MAILER_SENDER_PASS= -MAILER_HOST=smtppro.zoho.in \ No newline at end of file +MAILER_HOST=smtppro.zoho.in + +REDIS_HOST=localhost +REDIS_PORT=6379 + +DEBUG=True +ENABLE_EMAIL_NOTIFICATIONS=False