UNPKG

@geniucode/common-utils

Version:

Common utils

24 lines 782 B
import { TErrors } from '@geniucode/terminator'; import * as jwt from '../utils/jwt'; export const authenticate = (tryNext = false) => { return (req, res, next) => { try { const accessToken = req.headers['x-access-token']; if (!accessToken) { throw new TErrors.NotAuthorizedError('x-access-token is empty'); } const payload = jwt.verifyMember(accessToken); req.currentUser = { ...payload, }; } catch (err) { const message = err.message ? err.message : err; if (!tryNext) { throw new TErrors.NotAuthorizedError(message); } } next(); }; }; //# sourceMappingURL=authenticate.js.map