From fce4974370e03fa6fb75141ab587f7f8e48745b2 Mon Sep 17 00:00:00 2001 From: Pranil Date: Wed, 29 Mar 2023 23:53:05 +0530 Subject: [PATCH] removed nullable operator from env variables --- src/controllers/todo.controller.ts | 1 + src/index.ts | 6 +++--- src/services/jwt.ts | 7 ++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/controllers/todo.controller.ts b/src/controllers/todo.controller.ts index 9f6bb6e..5d342fe 100644 --- a/src/controllers/todo.controller.ts +++ b/src/controllers/todo.controller.ts @@ -207,6 +207,7 @@ class TodoController { user: user.id, }); await todo.save(); + socket .to(user.id) .emit("todo_operation", { operation: "create", data: todo }); diff --git a/src/index.ts b/src/index.ts index a82a20c..03051fd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -40,11 +40,11 @@ const mongooseOptions = { serverSelectionTimeoutMS: 5000, }; -const MONGODB_URI = process.env.MONGODB_URI || ""; +const MONGODB_URI = process.env.MONGODB_URI; mongoose .set("strictQuery", true) - .connect(MONGODB_URI, mongooseOptions) + .connect(MONGODB_URI!, mongooseOptions) .then(() => { server.listen(PORT, () => { console.log(`Server is running on ${PORT}`); @@ -52,7 +52,7 @@ mongoose io.use((socket, next) => { const token = socket.handshake.auth.auth_token; // console.log("token is " + token); - jwt.verify(token, JWT_KEY, (err: any, user: any) => { + jwt.verify(token, JWT_KEY!, (err: any, user: any) => { if (err) { console.log("Error", err); } diff --git a/src/services/jwt.ts b/src/services/jwt.ts index 462c012..48447c1 100644 --- a/src/services/jwt.ts +++ b/src/services/jwt.ts @@ -13,10 +13,11 @@ class JWT { const authHeader = req.headers.authorization; if (authHeader && authHeader !== "null") { // const token = authHeader.split(" ")[1]; - log("auth Header", JWT_KEY); - jwt.verify(authHeader, JWT_KEY, (err: any, user: any) => { + // log("auth Header", JWT_KEY); + jwt.verify(authHeader, JWT_KEY!, (err: any, user: any) => { if (err) { - log("Error", err); + console.log("in jwt service"); + console.log("Error", err); return res .status(403) .send({ success: false, message: "Token Expired" });