-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backend/frontend/shared): forgot-password-functionality bb-188 (#…
…230) * feat: first implementation of email-sending part bb-188 * feat: changed forgot password endpooint return value bb-188 * fix: fixing default_forgot_password_payload import bb-188 * fix: renamed back to constants.ts bb-188 * refactor: moved default_payload consts for auth forms into constants folders bb-188 * feat: forgot-password endpoints don't return a value bb-188 * feat: added swagger doc for forgot-password reset-password enpoints bb-188 * refactor: added patch method to repository bb-188 * refactor: addressed own comments on pull request bb-188 * refactor: merged main bb-188 * refactor: addressed pr comment changes, removed patch payload bb-188 * refactor: changed naming for service and repository from findbyid to find bb-188 * refactor: addressed pr comments bb-188 * fix: removed .js import from sign up form on mobile bb-188 * fix: brought react import back to sign up form on mobile bb-188 * refactor: created a separate type for reset-password-form validation inside of use app form bb-188 * refactor: intermediate commit bb-188 * refactor: addressed pr comments bb-188 * refactor: self-assesment fixes bb-188 * fix: brought back exports for UserValidationMessage bb-188 * refactor: addressed pull request comments bb-188 * feat: added toggle visibility for reset password inputs bb-188 * refactor: addressed pull request comments bb-188 * refactor: merged main bb-188 * fix: removed react import from use-query hook definition bb-188 * refactor: addressed pull request comments bb-188 * refactor: rewritten mailer to spread config.ENV.MAILER when creating mailer instance bb-188 * refactor: renamed inputs to settings bb-188 * refactor: created a new type for authRouteToHeader key bb-188 * refactor: merged main bb-188 * refactor: adressed pull request comments bb-188 * refactor: adressed pull request comments bb-188 * fix: fixed typo bb-188 --------- Co-authored-by: Farid Shabanov <[email protected]>
- Loading branch information
Showing
64 changed files
with
1,877 additions
and
932 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { MailError } from "./mail-error.exception.js"; | ||
export { ValidationError } from "shared"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { type HTTPCode } from "~/libs/modules/http/http.js"; | ||
import { HTTPError } from "~/libs/modules/http/http.js"; | ||
import { type ValueOf } from "~/libs/types/types.js"; | ||
|
||
type Constructor = { | ||
cause?: unknown; | ||
message: string; | ||
status: ValueOf<typeof HTTPCode>; | ||
}; | ||
|
||
class MailError extends HTTPError { | ||
public constructor({ cause, message, status }: Constructor) { | ||
super({ cause, message, status }); | ||
} | ||
} | ||
|
||
export { MailError }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
apps/backend/src/libs/modules/mailer/base-mailer.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { createTransport, type Transporter } from "nodemailer"; | ||
|
||
import { ErrorMessage } from "~/libs/enums/enums.js"; | ||
import { MailError } from "~/libs/exceptions/exceptions.js"; | ||
import { config } from "~/libs/modules/config/config.js"; | ||
import { HTTPCode } from "~/libs/modules/http/http.js"; | ||
|
||
type Constructor = { | ||
address: string; | ||
appPassword: string; | ||
host: string; | ||
port: number; | ||
service: string; | ||
}; | ||
|
||
class BaseMailer { | ||
private sender = config.ENV.MAILER.ADDRESS; | ||
private transporter: Transporter; | ||
|
||
constructor(settings: Constructor) { | ||
this.transporter = createTransport({ | ||
auth: { | ||
pass: settings.appPassword, | ||
user: settings.address, | ||
}, | ||
host: settings.host, | ||
port: settings.port, | ||
secure: true, | ||
service: settings.service, | ||
}); | ||
} | ||
|
||
public sendEmail({ | ||
subject, | ||
text, | ||
to, | ||
}: { | ||
subject: string; | ||
text: string; | ||
to: string; | ||
}): void { | ||
this.transporter.sendMail( | ||
{ | ||
from: this.sender, | ||
subject, | ||
text, | ||
to, | ||
}, | ||
(error) => { | ||
throw new MailError({ | ||
cause: (error as Error).cause, | ||
message: ErrorMessage.MAIL_ERROR, | ||
status: HTTPCode.INTERNAL_SERVER_ERROR, | ||
}); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
export { BaseMailer }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { config } from "~/libs/modules/config/config.js"; | ||
|
||
import { BaseMailer } from "./base-mailer.module.js"; | ||
|
||
const { ADDRESS, APP_PASSWORD, HOST, PORT, SERVICE } = config.ENV.MAILER; | ||
|
||
const mailer = new BaseMailer({ | ||
address: ADDRESS, | ||
appPassword: APP_PASSWORD, | ||
host: HOST, | ||
port: PORT, | ||
service: SERVICE, | ||
}); | ||
|
||
export { mailer }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.