Merge branch 'main' of git.odit.services:lfk/backend into main

This commit is contained in:
Nicolai Ort 2020-11-25 19:52:33 +01:00
commit 8c04bd067c
5 changed files with 41 additions and 6 deletions

View File

@ -1,4 +0,0 @@
{
"tabWidth": 4,
"useTabs": false
}

12
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,12 @@
{
"editor.formatOnSave": true,
"typescript.format.enable": true,
"typescript.preferences.quoteStyle": "single",
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"prettier.enable": false,
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
}
}

View File

@ -0,0 +1,17 @@
import { Request, Response, NextFunction } from "express";
// import bodyParser from 'body-parser';
// import cors from 'cors';
import * as jwt from "jsonwebtoken";
export default (req: Request, res: Response, next: NextFunction) => {
const token = <string>req.headers["auth"];
try {
const jwtPayload = <any>jwt.verify(token, "secretjwtsecret");
// const jwtPayload = <any>jwt.verify(token, process.env.JWT_SECRET);
res.locals.jwtPayload = jwtPayload;
} catch (error) {
console.log(error);
return res.status(401).send();
}
next();
};

10
src/routes/v1/test.ts Normal file
View File

@ -0,0 +1,10 @@
import { Router } from "express";
import jwtauth from "../../middlewares/jwtauth";
const router = Router();
router.use("*", jwtauth, async (req, res, next) => {
return res.send("ok");
});
export default router;

View File

@ -5,8 +5,8 @@
"rootDir": "./src", "rootDir": "./src",
"outDir": "./build", "outDir": "./build",
"esModuleInterop": true, "esModuleInterop": true,
"strict": true, "strict": false,
"experimentalDecorators": true, "experimentalDecorators": true,
"emitDecoratorMetadata":true "emitDecoratorMetadata": true
} }
} }