v.2.1.20230102
skitsanos
released this
02 Jan 16:45
·
31 commits
to master
since this release
- Added
auth
utility intomodule.context
withencode
,decode
andisExpired
methods to handle JWT tokens - Routes can require JWT authentication:
module.context.use((req, res, next) =>
{
if (req.path === '/' || req.path.match(/\/(login|signup)/igu))
{
next();
}
else
{
const {authorization} = req.headers;
if (!authorization)
{
res.throw(403, 'Missing authorization header');
}
const token = authorization && authorization.split(' ')[1];
try
{
const {auth} = module.context;
if (auth.isExpired(token))
{
res.throw(403, 'The token is expired');
}
next();
}
catch (e)
{
res.throw(403, e.message);
}
}
});
- CircleCI flow updated to use Node 18