Skip to content

Commit

Permalink
feat: implement magic link endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
masterchief-Dave committed Jul 29, 2024
1 parent 8cb1fa6 commit 7a159f7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ DB_PASSWORD=,
DB_PORT=,
DB_NAME=,
TOKEN_SECRET=
TOKEN_EXPIRY=
SMTP_USER=,
SMTP_PASSWORD=,
SMTP_HOST=,
Expand All @@ -28,3 +29,4 @@ GOOGLE_AUTH_CALLBACK_URL=
FLW_PUBLIC_KEY=
FLW_SECRET_KEY=
FLW_ENCRYPTION_KEY=
BASE_URL=
4 changes: 3 additions & 1 deletion src/controllers/AuthController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand All @@ -458,6 +459,7 @@ const createMagicToken = async (
status_code: 400,
});
}
console.log(error);
const err = new Error("Server Error");
next(error);
}
Expand Down
44 changes: 22 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -49,7 +49,7 @@ server.use(
],
}),
);
server.use("/api/v1", authRoute);

server.use(Limiter);
server.use(express.json());
server.use(express.urlencoded({ extended: true }));
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/utils/mail.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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");
}
};
Expand Down

0 comments on commit 7a159f7

Please sign in to comment.