basic jwt auth test
This commit is contained in:
parent
8e8aa774bc
commit
3a84cc8ef5
|
@ -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();
|
||||
};
|
|
@ -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;
|
Loading…
Reference in New Issue