koa-authentication-middleware
Usage example
- Сначала нужно cформировать подписанный токен
const sign = jwt.sign(
{
userId: 'some user id',
},
'secretKey',
);
И кладем в заголовок Authorization: Bearer ${sign}
- Теперь осталось тодько обернуть роуты мидлаваром
import koaAuthenticationMiddleware from 'koa-authentication-middleware'
router.get('/route', koaAuthenticationMiddleware('secretKey'), async ctx => {
console.log(ctx.state.userId);
});