Skip to content

Commit ec8b588

Browse files
author
root
committed
Add email verification and SMTP configuration
- Updated .env.example to include SMTP settings and email verification parameters. - Modified docker-compose.yml to add MailHog service for email testing and configured environment variables for the auth service. - Implemented MailService for sending verification emails in auth service. - Added EmailVerification model to Prisma schema and corresponding migration. - Updated auth controller and service to handle email verification logic. - Adjusted CORS settings across services to use the production frontend URL. - Cleaned up unused OAuth guards and strategies in the auth service.
1 parent b0b9f2f commit ec8b588

48 files changed

Lines changed: 605 additions & 1217 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.example

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,21 @@ AUTH_PORT=
1212

1313
AUTH_SERVICE_URL=
1414

15-
PROFILES_SERVICE_URL=
15+
PROFILES_SERVICE_URL=
16+
17+
SMTP_HOST=
18+
SMTP_PORT=
19+
SMTP_SECURE=
20+
SMTP_USER=
21+
SMTP_PASS=
22+
SMTP_FROM=
23+
EMAIL_VERIFY_URL_BASE=
24+
EMAIL_VERIFY_TTL_HOURS=
25+
EMAIL_VERIFY_AUTO=
26+
MAILHOG_UI_USER=
27+
MAILHOG_UI_PASS=
28+
SEED_EMAIL=
29+
SEED_PASSWORD=
30+
SEED_FIRST_NAME=
31+
SEED_LAST_NAME=
32+
SEED_DEMO=

backend/devops/backend-services/security/modsecurity/default.conf

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,6 @@ upstream planner_upstream {
4949
server planner:7000;
5050
}
5151

52-
upstream swagger_upstream {
53-
server swagger:8080;
54-
}
55-
56-
upstream netdata_upstream {
57-
server netdata:19999;
58-
}
59-
6052
server {
6153
listen 443 ssl;
6254
server_name auth.localhost;
@@ -78,34 +70,9 @@ server {
7870
}
7971
}
8072

81-
server {
82-
listen 443 ssl;
83-
server_name netdata.localhost;
84-
85-
access_log /dev/stdout gateway_log;
86-
error_log /dev/stderr warn;
87-
88-
ssl_protocols TLSv1.2 TLSv1.3;
89-
ssl_certificate /etc/nginx/conf/server.crt;
90-
ssl_certificate_key /etc/nginx/conf/server.key;
91-
92-
proxy_set_header Host $host;
93-
proxy_set_header X-Real-IP $remote_addr;
94-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
95-
proxy_set_header X-Forwarded-Proto $scheme;
96-
97-
location / {
98-
proxy_http_version 1.1;
99-
proxy_set_header Upgrade $http_upgrade;
100-
proxy_set_header Connection $connection_upgrade;
101-
proxy_pass http://netdata_upstream;
102-
}
103-
}
104-
105-
10673
server {
10774
listen 443 ssl default_server;
108-
server_name _ localhost;
75+
server_name 137.184.159.183;
10976

11077
access_log /dev/stdout gateway_log;
11178
error_log /dev/stderr warn;
@@ -213,19 +180,6 @@ server {
213180
proxy_set_header Connection $connection_upgrade;
214181
proxy_pass http://friends_ws_upstream;
215182
}
216-
217-
location /docs/ {
218-
proxy_pass http://swagger_upstream/;
219-
}
220-
221-
location = /netdata {
222-
return 308 https://netdata.localhost:8080/;
223-
}
224-
225-
location /netdata/ {
226-
return 308 https://netdata.localhost:8080/$is_args$args;
227-
}
228-
229183
location / {
230184
proxy_pass http://frontend_upstream;
231185
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mailhog:$apr1$TVIdd.rw$yib.BVXoOFmA2CYeEqxQC/

backend/src/ai-places-service/src/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const app = express();
1414
const PORT = process.env.PORT || 4000;
1515

1616
app.use(cors({
17-
origin: process.env.FRONTEND_URL || 'https://localhost',
17+
origin: process.env.FRONTEND_URL || 'https://rihla.tech',
1818
credentials: true,
1919
}));
2020
app.use(express.json());

backend/src/auth-service/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ COPY tsconfig*.json nest-cli.json ./
1414
COPY src ./src
1515

1616
RUN npx nest build
17+
18+
# make seed scripts available in build stage
19+
COPY scripts ./scripts
20+
21+
# Compile seed scripts to CommonJS so they can be run with plain Node
22+
RUN npx tsc scripts/seed-faker.ts --outDir scripts-compiled --module commonjs --target es2020 --esModuleInterop
1723

1824
FROM node:20-alpine
1925

@@ -29,6 +35,10 @@ COPY --from=build /app/package.json ./package.json
2935

3036
COPY prisma ./prisma
3137

38+
# Ensure runtime has access to TypeScript seed scripts used by the entrypoint
39+
COPY scripts ./scripts
40+
COPY --from=build /app/scripts-compiled ./scripts-compiled
41+
3242
COPY --chmod=700 entrypoint.sh /usr/local/bin/entrypoint.sh
3343

3444
EXPOSE 3001

backend/src/auth-service/entrypoint.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,23 @@ rm -f /tmp/db_data /tmp/auth_data
4040
echo "[auth-service] Running Prisma migrations..."
4141
npx prisma migrate deploy
4242

43+
echo "[auth-service] Generating Prisma client..."
44+
npx prisma generate
45+
46+
if [ "${SEED_DEMO:-}" = "true" ]; then
47+
echo "[auth-service] Seeding demo user..."
48+
# Prefer compiled JS seed if available (use absolute paths)
49+
if [ -f /app/scripts-compiled/seed-faker.js ]; then
50+
node /app/scripts-compiled/seed-faker.js
51+
else
52+
# Try ESM-aware ts-node first, fall back to regular ts-node
53+
if npx ts-node-esm /app/scripts/seed-faker.ts 2>/dev/null; then
54+
:
55+
else
56+
npx ts-node /app/scripts/seed-faker.ts
57+
fi
58+
fi
59+
fi
60+
4361
echo "[auth-service] Starting server on port ${AUTH_PORT:-3001}..."
4462
exec node dist/main

backend/src/auth-service/package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/src/auth-service/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"class-validator": "^0.14.3",
3131
"cookie-parser": "^1.4.7",
3232
"dotenv": "^17.3.1",
33+
"nodemailer": "^6.10.1",
3334
"passport": "^0.7.0",
3435
"passport-google-oauth20": "^2.0.0",
3536
"passport-jwt": "^4.0.1",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- CreateTable
2+
CREATE TABLE "EmailVerification" (
3+
"id" TEXT NOT NULL,
4+
"userId" TEXT NOT NULL,
5+
"tokenHash" TEXT NOT NULL,
6+
"expiresAt" TIMESTAMP(3) NOT NULL,
7+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
8+
9+
CONSTRAINT "EmailVerification_pkey" PRIMARY KEY ("id")
10+
);
11+
12+
-- CreateIndex
13+
CREATE UNIQUE INDEX "EmailVerification_userId_tokenHash_key" ON "EmailVerification"("userId", "tokenHash");
14+
15+
-- CreateIndex
16+
CREATE INDEX "EmailVerification_userId_idx" ON "EmailVerification"("userId");
17+
18+
-- AddForeignKey
19+
ALTER TABLE "EmailVerification" ADD CONSTRAINT "EmailVerification_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

backend/src/auth-service/prisma/schema.prisma

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ model User {
1616
updatedAt DateTime @updatedAt
1717
1818
accounts Account[]
19+
emailVerifications EmailVerification[]
1920
profile Profile?
2021
}
2122

@@ -48,3 +49,16 @@ model Profile {
4849
4950
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
5051
}
52+
53+
model EmailVerification {
54+
id String @id @default(cuid())
55+
userId String
56+
tokenHash String
57+
expiresAt DateTime
58+
createdAt DateTime @default(now())
59+
60+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
61+
62+
@@index([userId])
63+
@@unique([userId, tokenHash])
64+
}

0 commit comments

Comments
 (0)