Skip to content

Commit

Permalink
refactor: use mailchannels module
Browse files Browse the repository at this point in the history
  • Loading branch information
Yizack committed Nov 14, 2024
1 parent b761a20 commit b33a9aa
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 112 deletions.
24 changes: 14 additions & 10 deletions .config/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export default defineNuxtConfig({
"@dargmuesli/nuxt-cookie-control",
"nuxt-auth-utils",
"nuxt-webhook-validators",
"@nuxthub/core"
"@nuxthub/core",
"nuxt-mailchannels"
],
hub: { database: true, blob: true, cache: true },
icon: {
Expand Down Expand Up @@ -84,6 +85,12 @@ export default defineNuxtConfig({
optional: []
}
},
mailchannels: {
from: {
email: `support@${SITE.domain}`,
name: `${SITE.name} Support`
}
},
runtimeConfig: {
secure: {
salt: ""
Expand All @@ -100,16 +107,13 @@ export default defineNuxtConfig({
clientSecret: ""
}
},
mail: {
mailchannels: {
apiKey: "",
from: "",
fromName: "",
host: "",
port: "",
login: "",
password: "",
dkimKey: "",
dkimSelector: ""
dkim: {
domain: SITE.domain,
privateKey: "",
selector: ""
}
},
cloudinary: {
name: "",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
"eslint": "^9.14.0",
"leaflet": "^1.9.4",
"leaflet-geosearch": "^4.0.0",
"nodemailer": "^6.9.16",
"nuxt": "^3.14.159",
"nuxt-auth-utils": "^0.5.2",
"nuxt-mailchannels": "^0.1.4",
"nuxt-twemoji": "3.6.2",
"nuxt-webhook-validators": "^0.1.3",
"sass": "^1.80.6",
Expand Down
25 changes: 16 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion server/api/account/data/request.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export default defineEventHandler(async (event) => {
downloadLink: `${url}/account-data/${encodeURIComponent(btoa(email))}/${userHash}`
});

await sendMail(config, {
const mailchannels = useMailChannels(event);
await mailchannels.send({
to: { email, name: user.name },
subject: "Account data request",
html
Expand Down
3 changes: 2 additions & 1 deletion server/api/billing/refund.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default defineEventHandler(async (event) => {

const config = useRuntimeConfig(event);

await sendMail(config, {
const mailchannels = useMailChannels(event);
await mailchannels.send({
to: {
email: config.mail.from,

Check failure on line 19 in server/api/billing/refund.post.ts

View workflow job for this annotation

GitHub Actions / test

'config.mail' is of type 'unknown'.
name: config.mail.fromName

Check failure on line 20 in server/api/billing/refund.post.ts

View workflow job for this annotation

GitHub Actions / test

'config.mail' is of type 'unknown'.
Expand Down
5 changes: 2 additions & 3 deletions server/api/billing/subscribe.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ export default defineEventHandler(async (event) => {
domain: SITE.domain
});

const config = useRuntimeConfig(event);

await sendMail(config, {
const mailchannels = useMailChannels(event);
await mailchannels.send({
to: {
email: user.email,
name: user.name
Expand Down
3 changes: 2 additions & 1 deletion server/api/recovery/request.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export default defineEventHandler(async (event) => {
recoveryLink: `${url}/recovery/${encodeURIComponent(btoa(user.email))}/${code}`
});

await sendMail(config, {
const mailchannels = useMailChannels(event);
await mailchannels.send({
to: { email, name: user.name },
subject: "Account recovery",
html
Expand Down
3 changes: 2 additions & 1 deletion server/api/signup.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ export default defineEventHandler(async (event) => {
verifyLink: `${url}/verify/${encodeURIComponent(btoa(email))}/${code}`
});

await sendMail(config, {
const mailchannels = useMailChannels(event);
await mailchannels.send({
to: { email, name: user.name },
subject: "Verify your email address",
html
Expand Down
3 changes: 2 additions & 1 deletion server/api/verify/resend.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export default defineEventHandler(async (event): Promise<{ email: string }> => {
verifyLink: `${url}/verify/${encodeURIComponent(btoa(email))}/${code}`
});

await sendMail(config, {
const mailchannels = useMailChannels(event);
await mailchannels.send({
to: { email, name },
subject: "Verify your email address",
html
Expand Down
3 changes: 2 additions & 1 deletion server/routes/auth/google-signup.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export default defineOAuthGoogleEventHandler({
verifyLink: `${url}/verify/${encodeURIComponent(btoa(email))}/${code}`
});

await sendMail(config, {
const mailchannels = useMailChannels(event);
await mailchannels.send({
to: { email, name: user.name },
subject: "Verify your email address",
html
Expand Down
83 changes: 0 additions & 83 deletions server/utils/mail.ts

This file was deleted.

0 comments on commit b33a9aa

Please sign in to comment.