forked from Deen-Bridge/dnb-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemailRoutes.js
More file actions
27 lines (23 loc) · 856 Bytes
/
Copy pathemailRoutes.js
File metadata and controls
27 lines (23 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import express from "express";
import logger from "../config/logger.js";
import { sendOtpEmail } from "../../services/emails/sendMail.js";
import { generateOtp } from "../utils/otp.js";
const router = express.Router();
router.post("/", async (req, res) => {
const { email } = req.body;
logger.info(`Received email: ${email}`);
// Validate email
if (!email || typeof email !== "string") {
return res.status(400).json({ message: "Invalid email format" });
}
if (!email) return res.status(400).json({ message: "Email is required" });
try {
const otp = generateOtp();
await sendOtpEmail(otp, email);
res.json({ success: true, message: "OTP sent" });
} catch (error) {
logger.error("Failed to send OTP:", error);
res.status(500).json({ success: false, message: "Failed to send OTP" });
}
});
export default router;