From 7a159f78d6c04b916722187cec0a9b12e9705a62 Mon Sep 17 00:00:00 2001 From: masterchief-Dave Date: Mon, 29 Jul 2024 15:50:44 +0100 Subject: [PATCH] feat: implement magic link endpoint --- .env.example | 2 ++ src/controllers/AuthController.ts | 4 ++- src/index.ts | 44 +++++++++++++++---------------- src/utils/mail.ts | 3 ++- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/.env.example b/.env.example index 873e273d..a9774858 100644 --- a/.env.example +++ b/.env.example @@ -6,6 +6,7 @@ DB_PASSWORD=, DB_PORT=, DB_NAME=, TOKEN_SECRET= +TOKEN_EXPIRY= SMTP_USER=, SMTP_PASSWORD=, SMTP_HOST=, @@ -28,3 +29,4 @@ GOOGLE_AUTH_CALLBACK_URL= FLW_PUBLIC_KEY= FLW_SECRET_KEY= FLW_ENCRYPTION_KEY= +BASE_URL= \ No newline at end of file diff --git a/src/controllers/AuthController.ts b/src/controllers/AuthController.ts index 6cd6b3e2..416d315d 100644 --- a/src/controllers/AuthController.ts +++ b/src/controllers/AuthController.ts @@ -433,7 +433,8 @@ const createMagicToken = async ( next: NextFunction, ) => { try { - const email = req.body.email; + const email = req.body?.email; + console.log(req.body); if (!email) { throw new BadRequest("Email is missing in request body."); } @@ -458,6 +459,7 @@ const createMagicToken = async ( status_code: 400, }); } + console.log(error); const err = new Error("Server Error"); next(error); } diff --git a/src/index.ts b/src/index.ts index dffbbb1a..b991121b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,37 +1,37 @@ // src/index.ts -import "reflect-metadata"; -import AppDataSource from "./data-source"; -import log from "./utils/logger"; +import cors from "cors"; +import dotenv from "dotenv"; import express, { Express, Request, Response } from "express"; +import "reflect-metadata"; +import swaggerUi from "swagger-ui-express"; import config from "./config"; -import dotenv from "dotenv"; -import cors from "cors"; +import passport from "./config/google.passport.config"; +import AppDataSource from "./data-source"; +import { authMiddleware, errorHandler, routeNotFound } from "./middleware"; import { - userRouter, + adminRouter, authRoute, - helpRouter, - testimonialRoute, - notificationRouter, - productRouter, - jobRouter, blogRouter, - adminRouter, - exportRouter, - sendEmailRoute, - paymentRouter, contactRouter, + exportRouter, + helpRouter, + jobRouter, + notificationRouter, paymentFlutterwaveRouter, + paymentRouter, paymentStripeRouter, + productRouter, + sendEmailRoute, + testimonialRoute, + userRouter, } from "./routes"; -import { smsRouter } from "./routes/sms"; -import { routeNotFound, errorHandler, authMiddleware } from "./middleware"; import { orgRouter } from "./routes/organisation"; -import swaggerUi from "swagger-ui-express"; -import swaggerSpec from "./swaggerConfig"; +import { smsRouter } from "./routes/sms"; import updateRouter from "./routes/updateOrg"; +import swaggerSpec from "./swaggerConfig"; import { Limiter } from "./utils"; +import log from "./utils/logger"; import ServerAdapter from "./views/bull-board"; -import passport from "./config/google.passport.config"; dotenv.config(); const port = config.port; @@ -49,7 +49,7 @@ server.use( ], }), ); -server.use("/api/v1", authRoute); + server.use(Limiter); server.use(express.json()); server.use(express.urlencoded({ extended: true })); @@ -63,7 +63,7 @@ server.get("/api/v1", (req: Request, res: Response) => { // }); server.use("/api/v1", userRouter); - +server.use("/api/v1", authRoute); server.use("/api/v1", adminRouter); server.use("/api/v1", sendEmailRoute); server.use("/api/v1/sms", smsRouter); diff --git a/src/utils/mail.ts b/src/utils/mail.ts index c3bc43b4..c67bb0f2 100644 --- a/src/utils/mail.ts +++ b/src/utils/mail.ts @@ -1,6 +1,7 @@ import nodemailer from "nodemailer"; import config from "../config"; import { BadRequest } from "../middleware"; +import log from "./logger"; const Sendmail = async (emailcontent: any) => { const transporter = nodemailer.createTransport({ @@ -17,7 +18,7 @@ const Sendmail = async (emailcontent: any) => { await transporter.sendMail(emailcontent); return "Email sent successfully."; } catch (error) { - console.log(error); + log.error(error); throw new BadRequest("Error sending email"); } };