Compare commits

...

5 Commits

Author SHA1 Message Date
3a84cc8ef5 basic jwt auth test 2020-11-25 19:47:17 +01:00
8e8aa774bc Merge branch 'main' of https://git.odit.services/lfk/backend into main 2020-11-25 19:42:54 +01:00
447f4d882f tsconfig not strict
ref #1
2020-11-25 19:42:22 +01:00
f96f5a63a4 remove prettier config
ref #1
2020-11-25 19:41:37 +01:00
b6ddda6cd8 vscode workspace settings.json
ref #1
2020-11-25 19:41:26 +01:00
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",
"outDir": "./build",
"esModuleInterop": true,
"strict": true,
"strict": false,
"experimentalDecorators": true,
"emitDecoratorMetadata":true
"emitDecoratorMetadata": true
}
}