UNPKG

mares-jwt

Version:

express.js 미들웨어를 이용하여 jwt 암호화, 복호화를 해주는 모듈입니다.

66 lines (60 loc) 1.23 kB
const MaresError = require('mares-error') const codes = { tokenExpiredError: 'tokenExpiredError', jsonWebTokenError: 'jsonWebTokenError', notBeforeError: 'notBeforeError' } /** * MaresJWTError class */ class MaresJWTError extends MaresError { /** * 에러 클래스 생성자 * @param {Object} input - 외부 error. */ constructor(input) { super(input) } /** * 에러 코드를 반환한다. * @returns {{tokenExpiredError: string, jsonWebTokenError: string, notBeforeError: string}} * @static */ static getCodes() { return codes } /** * jwt error 를 mares error object 로 변환한다. * @override * @returns {{status: number, body: {}}} */ convert() { let body = {} let status = 401 switch (this.input.name) { case 'TokenExpiredError': body = { msg: codes.tokenExpiredError, code: codes.tokenExpiredError } break case 'JsonWebTokenError': body = { msg: codes.jsonWebTokenError, code: codes.jsonWebTokenError } break case 'NotBeforeError': body = { msg: codes.notBeforeError, code: codes.notBeforeError } break } return { status, body: {rows: [body]} } } } module.exports = MaresJWTError