improved auth logging

This commit is contained in:
kyle hoell
2020-12-03 04:31:47 -05:00
parent 83fd29d328
commit 93b33ea0d6
9 changed files with 31 additions and 25 deletions
+5 -1
View File
@@ -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");
}
}
+5 -1
View File
@@ -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");
}
}
+4 -3
View File
@@ -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");
}
@@ -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");
}
}
+5 -10
View File
@@ -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");
}
}
+8 -4
View File
@@ -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");
}
}
@@ -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);
@@ -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);
@@ -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);