From 93b33ea0d645fd7f2a07fbd3344e68e6e4218009 Mon Sep 17 00:00:00 2001 From: kyle hoell Date: Thu, 3 Dec 2020 04:31:47 -0500 Subject: [PATCH] improved auth logging --- backend/middleware/auth.ts | 6 +++++- backend/middleware/authFullUser.ts | 6 +++++- backend/middleware/authLogout.ts | 7 ++++--- backend/middleware/authNoEmailVerificication.ts | 7 ++++--- backend/middleware/authRefresh.ts | 15 +++++---------- backend/middleware/authStreamVideo.ts | 12 ++++++++---- .../services/ChunkService/FileSystemService.ts | 1 - backend/services/ChunkService/MongoService.ts | 1 - backend/services/ChunkService/S3Service.ts | 1 - 9 files changed, 31 insertions(+), 25 deletions(-) diff --git a/backend/middleware/auth.ts b/backend/middleware/auth.ts index 47f43d6..158a536 100644 --- a/backend/middleware/auth.ts +++ b/backend/middleware/auth.ts @@ -47,7 +47,11 @@ const auth = async(req: RequestType, res: Response, next: NextFunction) => { next(); } catch (e) { - console.log("\nAuthorization Middleware Error:", e.message); + + if (e.message !== "No Access Token" && + e.message !== "No User" && + e.message !== "Email Not Verified") console.log("\nAuthorization Middleware Error:", e.message); + res.status(401).send("Error Authenticating"); } } diff --git a/backend/middleware/authFullUser.ts b/backend/middleware/authFullUser.ts index 34b2213..5dbb4dd 100644 --- a/backend/middleware/authFullUser.ts +++ b/backend/middleware/authFullUser.ts @@ -47,7 +47,11 @@ const authFullUser = async(req: RequestType, res: Response, next: NextFunction) next(); } catch (e) { - console.log("\nAuthorization Middleware Error:", e.message); + + if (e.message !== "No Access Token" && + e.message !== "No User" && + e.message !== "Email Not Verified") console.log("\nAuthorization Full User Middleware Error:", e.message); + res.status(401).send("Error Authenticating"); } } diff --git a/backend/middleware/authLogout.ts b/backend/middleware/authLogout.ts index e6e1218..2a1bbe0 100644 --- a/backend/middleware/authLogout.ts +++ b/backend/middleware/authLogout.ts @@ -26,8 +26,6 @@ const auth = async(req: RequestType, res: Response, next: NextFunction) => { try { - console.log("\nAUTH NO EMAIL"); - const accessToken = req.cookies["access-token"]; if (!accessToken) throw new Error("No Access Token"); @@ -43,7 +41,10 @@ const auth = async(req: RequestType, res: Response, next: NextFunction) => { next(); } catch (e) { - console.log("\nAuthorization Middleware No Email Verifiaction Error:", e.message); + + if (e.message !== "No Access Token" && + e.message !== "No User") console.log("\nAuthorization Logout Middleware Error:", e.message); + createLogoutCookie(res); return res.status(401).send("Error Authenticating"); } diff --git a/backend/middleware/authNoEmailVerificication.ts b/backend/middleware/authNoEmailVerificication.ts index 51eb961..314fb37 100644 --- a/backend/middleware/authNoEmailVerificication.ts +++ b/backend/middleware/authNoEmailVerificication.ts @@ -26,8 +26,6 @@ const auth = async(req: RequestType, res: Response, next: NextFunction) => { try { - console.log("\nAUTH NO EMAIL"); - const accessToken = req.cookies["access-token"]; if (!accessToken) throw new Error("No Access Token"); @@ -48,7 +46,10 @@ const auth = async(req: RequestType, res: Response, next: NextFunction) => { next(); } catch (e) { - console.log("\nAuthorization Middleware No Email Verifiaction Error:", e.message); + + if (e.message !== "No Access Token" && + e.message !== "No User") console.log("\nAuthorization No Email Verification Middleware Error:", e.message); + return res.status(401).send("Error Authenticating"); } } diff --git a/backend/middleware/authRefresh.ts b/backend/middleware/authRefresh.ts index 633aa9d..0d22414 100644 --- a/backend/middleware/authRefresh.ts +++ b/backend/middleware/authRefresh.ts @@ -16,11 +16,6 @@ type jwtType = { time: number } -// type userAccessType = { -// _id: string, -// emailVerified: boolean, -// email: string, -// } const removeOldTokens = async(userID: string, ipAddress: string | undefined, oldTime: number) => { try { @@ -42,10 +37,6 @@ const authRefresh = async(req: RequestType, res: Response, next: NextFunction) = try { - console.log("\nrefresh token auth") - - //if (true === true) throw new Error("test"); - const refreshToken = req.cookies["refresh-token"]; if (!refreshToken) throw new Error("No Refresh Token"); @@ -82,7 +73,11 @@ const authRefresh = async(req: RequestType, res: Response, next: NextFunction) = next(); } catch (e) { - console.log("\nAuthorization Refresh Middleware Error:", e.message); + + if (e.message !== "No Refresh Token" && + e.message !== "No User" && + e.message !== "Refresh Token Not Found") console.log("\nAuthorization Refresh Middleware Error:", e.message); + res.status(401).send("Error Refreshing Token"); } } diff --git a/backend/middleware/authStreamVideo.ts b/backend/middleware/authStreamVideo.ts index fd3db9b..56e7895 100644 --- a/backend/middleware/authStreamVideo.ts +++ b/backend/middleware/authStreamVideo.ts @@ -55,7 +55,7 @@ const authStreamVideo = async(req: RequestType, res: Response, next: NextFunctio const accessTokenStreamVideo = req.cookies["video-access-token"]; - if (!accessTokenStreamVideo) throw new Error("No Stream Video Access Token"); + if (!accessTokenStreamVideo) throw new Error("No Access Token"); const decoded = jwt.verify(accessTokenStreamVideo, env.passwordAccess!) as jwtType; @@ -63,7 +63,7 @@ const authStreamVideo = async(req: RequestType, res: Response, next: NextFunctio const user = await User.findById(new ObjectID(decoded._id)); - if (!user) throw new Error("No User Stream Video"); + if (!user) throw new Error("No User"); const encrpytionKey = user.getEncryptionKey(); const encryptedToken = user.encryptToken(accessTokenStreamVideo, encrpytionKey, decoded.iv); @@ -82,7 +82,7 @@ const authStreamVideo = async(req: RequestType, res: Response, next: NextFunctio } } - if (!tokenFound) throw new Error("Refresh Token Not Found"); + if (!tokenFound) throw new Error("Access Token Not Found"); req.user = user; req.accessTokenStreamVideo = encryptedToken; @@ -90,7 +90,11 @@ const authStreamVideo = async(req: RequestType, res: Response, next: NextFunctio next(); } catch (e) { - console.log("\nAuthorization Middleware Error:", e.message); + + if (e.message !== "No Access Token" && + e.message !== "No User" && + e.message !== "Access Token Not Found") console.log("\nAuthorization Stream Video Middleware Error:", e.message); + res.status(401).send("Error Authenticating"); } } diff --git a/backend/services/ChunkService/FileSystemService.ts b/backend/services/ChunkService/FileSystemService.ts index d2322fb..2231933 100644 --- a/backend/services/ChunkService/FileSystemService.ts +++ b/backend/services/ChunkService/FileSystemService.ts @@ -268,7 +268,6 @@ class FileSystemService implements ChunkInterface { // And and helping me understand how the IVs work. // Also fuck you Apple, Safari is turning into // Internet explorer at this point. - // Thanks Tim Apple const userID = user._id; const currentFile: FileInterface = await dbUtilsFile.getFileInfo(fileID, userID); diff --git a/backend/services/ChunkService/MongoService.ts b/backend/services/ChunkService/MongoService.ts index a889404..4e8bde0 100644 --- a/backend/services/ChunkService/MongoService.ts +++ b/backend/services/ChunkService/MongoService.ts @@ -284,7 +284,6 @@ class MongoService implements ChunkInterface { // And and helping me understand how the IVs work. // Also fuck you Apple, Safari is turning into // Internet explorer at this point. - // Thanks Tim Apple const userID = user._id; const currentFile = await dbUtilsFile.getFileInfo(fileID, userID); diff --git a/backend/services/ChunkService/S3Service.ts b/backend/services/ChunkService/S3Service.ts index 49a8162..87f0ed5 100644 --- a/backend/services/ChunkService/S3Service.ts +++ b/backend/services/ChunkService/S3Service.ts @@ -250,7 +250,6 @@ class S3Service implements ChunkInterface { // And and helping me understand how the IVs work. // Also fuck you Apple, Safari is turning into // Internet explorer at this point. - // Thanks Tim Apple const userID = user._id; const currentFile: FileInterface = await dbUtilsFile.getFileInfo(fileID, userID);