Merge branch 'main' of git.odit.services:lfk/backend into main
This commit is contained in:
commit
8c04bd067c
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"tabWidth": 4,
|
|
||||||
"useTabs": false
|
|
||||||
}
|
|
12
.vscode/settings.json
vendored
Normal file
12
.vscode/settings.json
vendored
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
17
src/middlewares/jwtauth.ts
Normal file
17
src/middlewares/jwtauth.ts
Normal 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
10
src/routes/v1/test.ts
Normal 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;
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user