new-koa-jwt
v1.0.3
Published
Koa.js middleware for validates a jwt
Downloads
2
Maintainers
Readme
new-koa-jwt
Example
import Koa from "koa";
import KoaJwt from "new-koa-jwt";
const app = new Koa();
const secret = process.env.secret || "secret";
app.use(KoaJwt({ secret }));
app.use((ctx) => {
const { data } = ctx.state.jwt;
ctx.body = data;
});
app.listen(3000);
Router
router.get('/users', koaJwt({ secret: 'secret' }), (ctx) => {
const { data: { username } } = ctx.state.jwt;
ctx.body = username;
});