JWT Autorization / Logging in and registering

This commit is contained in:
2020-07-19 14:35:51 +02:00
parent a267dd1f37
commit 9f4f5347d4
279 changed files with 23396 additions and 33 deletions

View File

@@ -32,29 +32,42 @@ const upload = multer({
limits: { fileSize: 4000000 },
}); //max file size = 4Mb
// POST
router.post("/", upload.single("menuiImage"), async (req, res) => {
try {
const image = req.file;
if (!image) {
res.sendStatus(204);
} else {
setTimeout(() => {
fs.unlink(image.path, (err) => {
if (err) {
console.log("No such file or directory");
}
});
}, 1000 * 600);
res
.status(200)
.cookie("img", encodeURI(image.path), {
maxAge: 1000 * 600,
})
.send();
}
} catch (err) {
res.sendStatus(500);
const token = req.headers["x-auth-token"];
if (!token) {
res.sendStatus(401);
return;
}
services.validateUserToken(token, (result) => {
if (!result) {
res.sendStatus(401);
} else {
try {
const image = req.file;
if (!image) {
res.sendStatus(204);
} else {
setTimeout(() => {
fs.unlink(image.path, (err) => {
if (err) {
console.log("No such file or directory");
}
});
}, 1000 * 600);
res
.status(200)
.cookie("img", encodeURI(image.path), {
maxAge: 1000 * 600,
})
.send();
}
} catch (err) {
res.sendStatus(500);
}
}
});
});
export default router;