@ahi40/common
Advanced tools
Comparing version 1.0.22 to 1.0.23
@@ -22,3 +22,3 @@ "use strict"; | ||
var _this = _super.call(this, 'Not Authorized.') || this; | ||
_this.statusCode = 403; | ||
_this.statusCode = 401; | ||
Object.setPrototypeOf(_this, NotAuthorizedError.prototype); | ||
@@ -25,0 +25,0 @@ return _this; |
import { CustomError } from './custom-error'; | ||
export declare class TokenExpiredError extends CustomError { | ||
export declare class TokenExpiredCustomError extends CustomError { | ||
statusCode: number; | ||
@@ -4,0 +4,0 @@ constructor(); |
@@ -16,17 +16,17 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TokenExpiredError = void 0; | ||
exports.TokenExpiredCustomError = void 0; | ||
var custom_error_1 = require("./custom-error"); | ||
var TokenExpiredError = /** @class */ (function (_super) { | ||
__extends(TokenExpiredError, _super); | ||
function TokenExpiredError() { | ||
var TokenExpiredCustomError = /** @class */ (function (_super) { | ||
__extends(TokenExpiredCustomError, _super); | ||
function TokenExpiredCustomError() { | ||
var _this = _super.call(this, 'Token expired.') || this; | ||
_this.statusCode = 402; | ||
Object.setPrototypeOf(_this, TokenExpiredError.prototype); | ||
_this.statusCode = 401; | ||
Object.setPrototypeOf(_this, TokenExpiredCustomError.prototype); | ||
return _this; | ||
} | ||
TokenExpiredError.prototype.serializeErrors = function () { | ||
TokenExpiredCustomError.prototype.serializeErrors = function () { | ||
return [{ message: 'Token expired. Please login again.' }]; | ||
}; | ||
return TokenExpiredError; | ||
return TokenExpiredCustomError; | ||
}(custom_error_1.CustomError)); | ||
exports.TokenExpiredError = TokenExpiredError; | ||
exports.TokenExpiredCustomError = TokenExpiredCustomError; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.currentUser = void 0; | ||
var jsonwebtoken_1 = __importDefault(require("jsonwebtoken")); | ||
var jsonwebtoken_1 = require("jsonwebtoken"); | ||
var token_expired_error_1 = require("../errors/token-expired-error"); | ||
exports.currentUser = function (req, res, next) { | ||
@@ -12,3 +10,2 @@ var _a; | ||
if (!((_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt)) { | ||
console.log('no jwt'); | ||
console.log(req.session); | ||
@@ -21,10 +18,13 @@ return next(); | ||
try { | ||
payload = jsonwebtoken_1.default.verify(req.session.jwt, process.env.JWT_KEY); | ||
payload = jsonwebtoken_1.verify(req.session.jwt, process.env.JWT_KEY); | ||
req.currentUser = payload; | ||
} | ||
catch (ex) { | ||
catch (err) { | ||
if (err instanceof jsonwebtoken_1.TokenExpiredError) { | ||
throw new token_expired_error_1.TokenExpiredCustomError(); | ||
} | ||
console.log('caught error verify'); | ||
console.log(ex.message); | ||
console.log(err.message); | ||
console.log('\n\n\n'); | ||
console.log(ex); | ||
console.log(err); | ||
} | ||
@@ -31,0 +31,0 @@ console.log('payload jwt'); |
@@ -6,12 +6,6 @@ "use strict"; | ||
exports.requireAuth = function (req, res, next) { | ||
console.log('run req auth'); | ||
if (!req.currentUser) { | ||
console.log('no user set'); | ||
throw new not_authorized_error_1.NotAuthorizedError(); | ||
} | ||
// if (req.currentUser.exp < Date.now().valueOf() / 1000) { | ||
// console.log('token expired') | ||
// throw new TokenExpiredError(); | ||
// } | ||
next(); | ||
}; |
{ | ||
"name": "@ahi40/common", | ||
"version": "1.0.22", | ||
"version": "1.0.23", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./build/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23211
527