Skip to content

Commit d070212

Browse files
committed
Add email connection for password reset
1 parent 41056bf commit d070212

File tree

4 files changed

+36
-19
lines changed

4 files changed

+36
-19
lines changed

.github/workflows/deploy.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ jobs:
6868
rsync -aqc docker-compose.yml ${{ secrets.ssh_connection }}:~/vectorapp/vector-portfolio/
6969
ssh -i ~/.ssh/id_rsa ${{ secrets.ssh_connection }} "
7070
cd ~/vectorapp/vector-portfolio/
71-
echo "${{ env.DOMAIN }}" > .env
7271
7372
mkdir -p .secrets
74-
echo "${{ secrets.payload_secret }}" > .secrets/payload-secret.txt
75-
echo "${{ secrets.postgres_password }}" > .secrets/postgres-password.txt
73+
echo "${{ secrets.payload-secret }}" > .secrets/payload-secret.txt
74+
echo "${{ secrets.postgres-password }}" > .secrets/postgres-password.txt
75+
echo "${{ secrets.email-password }}" > .secrets/email-password.txt
7676
"
7777
- name: Build and push changes
7878
run: |
@@ -94,6 +94,7 @@ jobs:
9494
rm nginx.tar.gz
9595
9696
export DOMAIN="${{ env.DOMAIN }}"
97+
export EMAIL_USER="${{ env.EMAIL_USER }}"
9798
docker compose up -d --no-build
9899
docker image prune -f
99100
"

docker-compose.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ services:
77
- images:/app/media
88
environment:
99
- NEXT_PUBLIC_PAYLOAD_URL=https://${DOMAIN:?Website domain required}
10+
- SMTP_HOST=${SMTP_HOST:?SMTP_HOST required for email functionality}
11+
- EMAIL_USER=${EMAIL_USER:?EMAIL_USER required for email functionality}
1012
depends_on:
1113
- postgres
1214
- nginx
1315
secrets:
1416
- postgres-password
1517
- payload-secret
18+
- email-password
1619
postgres:
1720
restart: unless-stopped
1821
image: postgres:17.5-alpine
@@ -45,4 +48,6 @@ secrets:
4548
postgres-password:
4649
file: .secrets/postgres-password.txt
4750
payload-secret:
48-
file: .secrets/payload-secret.txt
51+
file: .secrets/payload-secret.txt
52+
email-password:
53+
file: .secrets/email-password.txt

src/lib/secrets.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import fs from 'node:fs'
22

3-
// Secrets loaded from files because they're inserted at build time by docker secrets
4-
// If no secret is found then read it from an environment variable (Mostly to allow for migrations and running node locally)
5-
export const PAYLOAD_SECRET = (() => {
3+
function readSecret(path: string, fallback: string = ''): string {
64
try {
7-
return fs.readFileSync('/run/secrets/payload-secret').toString()
5+
return fs.readFileSync(path).toString()
86
} catch {
9-
return process.env.PAYLOAD_SECRET || ''
7+
return fallback || ''
108
}
11-
})()
9+
}
1210

13-
export const DATABASE_URI = (() => {
14-
try {
15-
const password = fs.readFileSync('/run/secrets/postgres-password').toString()
16-
return `postgres://postgres:${password}@postgres:5432/postgres`
17-
} catch {
18-
return process.env.DATABASE_URI || ''
19-
}
20-
})()
11+
// Secrets loaded from files because they're inserted at build time by docker secrets
12+
// If no secret is found then read it from an environment variable (Mostly to allow for migrations and running node locally)
13+
export const PAYLOAD_SECRET = readSecret('/run/secrets/payload-secret', process.env.PAYLOAD_SECRET)
14+
15+
export const DATABASE_URI =
16+
process.env.DATABASE_URI ||
17+
`postgres://postgres:${readSecret('/run/secrets/postgres-password')}@postgres:5432/postgres`
18+
export const EMAIL_PASSWORD = readSecret('/run/secrets/email-password', process.env.EMAIL_PASSWORD)

src/payload.config.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// storage-adapter-import-placeholder
22
import { postgresAdapter } from '@payloadcms/db-postgres'
33
import { payloadCloudPlugin } from '@payloadcms/payload-cloud'
4-
import { PAYLOAD_SECRET } from './lib/secrets'
4+
import { EMAIL_PASSWORD, PAYLOAD_SECRET } from './lib/secrets'
55
import { DATABASE_URI } from './lib/secrets'
6+
import { nodemailerAdapter } from '@payloadcms/email-nodemailer'
67

78
import {
89
lexicalEditor,
@@ -65,6 +66,18 @@ export default buildConfig({
6566
}
6667
: false,
6768
},
69+
email: nodemailerAdapter({
70+
defaultFromAddress: 'contact@vectorinterior.design',
71+
defaultFromName: 'Vector: Interior Design',
72+
transportOptions: {
73+
host: process.env.SMTP_HOST,
74+
port: 587,
75+
auth: {
76+
user: process.env.EMAIL_USER,
77+
pass: EMAIL_PASSWORD,
78+
},
79+
},
80+
}),
6881
localization: {
6982
locales: ['en', 'es'],
7083
defaultLocale: 'es',

0 commit comments

Comments
 (0)