@based/server
Advanced tools
Comparing version 2.8.4 to 2.8.5
@@ -18,6 +18,10 @@ "use strict"; | ||
client.authorizeInProgress.then(() => { | ||
(0, authorize_1.default)(server, client, messages).then((messages) => { | ||
(0, authorize_1.default)(server, client, messages) | ||
.then((messages) => { | ||
if (messages) { | ||
(0, messageParser_1.default)(server, client, messages); | ||
} | ||
}) | ||
.catch((err) => { | ||
console.error('Error with authorize', err); | ||
}); | ||
@@ -27,6 +31,10 @@ }); | ||
else { | ||
(0, authorize_1.default)(server, client, messages).then((messages) => { | ||
(0, authorize_1.default)(server, client, messages) | ||
.then((messages) => { | ||
if (messages) { | ||
(0, messageParser_1.default)(server, client, messages); | ||
} | ||
}) | ||
.catch((err) => { | ||
console.error('Error with authorize', err); | ||
}); | ||
@@ -43,6 +51,10 @@ } | ||
client.authorizeInProgress.then(() => { | ||
(0, authorize_1.default)(server, client, messages).then((messages) => { | ||
(0, authorize_1.default)(server, client, messages) | ||
.then((messages) => { | ||
if (messages) { | ||
(0, messageParser_1.default)(server, client, messages); | ||
} | ||
}) | ||
.catch((err) => { | ||
console.error('Error with authorize', err); | ||
}); | ||
@@ -52,6 +64,10 @@ }); | ||
else { | ||
(0, authorize_1.default)(server, client, messages).then((messages) => { | ||
(0, authorize_1.default)(server, client, messages) | ||
.then((messages) => { | ||
if (messages) { | ||
(0, messageParser_1.default)(server, client, messages); | ||
} | ||
}) | ||
.catch((err) => { | ||
console.error('Error with authorize', err); | ||
}); | ||
@@ -58,0 +74,0 @@ } |
@@ -10,18 +10,23 @@ "use strict"; | ||
const jwtDecode = (resolve, reject, value, publicKey) => { | ||
jsonwebtoken_1.default.verify(value, publicKey, (err, decoded) => { | ||
if (err) { | ||
if (err instanceof jsonwebtoken_1.default.TokenExpiredError) { | ||
const basedError = new types_1.BasedError('Token expired'); | ||
basedError.code = types_1.BasedErrorCodes.TokenExpired; | ||
basedError.stack = err.stack; | ||
reject(basedError); | ||
try { | ||
jsonwebtoken_1.default.verify(value, publicKey, (err, decoded) => { | ||
if (err) { | ||
if (err instanceof jsonwebtoken_1.default.TokenExpiredError) { | ||
const basedError = new types_1.BasedError('Token expired'); | ||
basedError.code = types_1.BasedErrorCodes.TokenExpired; | ||
basedError.stack = err.stack; | ||
reject(basedError); | ||
} | ||
else { | ||
resolve(false); | ||
} | ||
} | ||
else { | ||
resolve(false); | ||
resolve(decoded); | ||
} | ||
} | ||
else { | ||
resolve(decoded); | ||
} | ||
}); | ||
}); | ||
} | ||
catch (err) { | ||
reject(err); | ||
} | ||
}; | ||
@@ -55,3 +60,3 @@ const getSecret = async (server, secret) => { | ||
exports.getSecret = getSecret; | ||
const cleanCarriageReturn = (value) => value.replace(/\n$/, ''); | ||
const cleanCarriageReturn = (value) => typeof value === 'string' ? value.replace(/\n$/, '') : value; | ||
const decodeToken = (value, publicKey) => { | ||
@@ -78,3 +83,4 @@ return new Promise((resolve, reject) => { | ||
} | ||
}).then((privateKey) => { | ||
}) | ||
.then((privateKey) => { | ||
if (privateKey) { | ||
@@ -96,3 +102,3 @@ const defaultOptions = { | ||
else { | ||
throw new Error(`Encode ${type} not implementedd yet`); | ||
reject(new Error(`Encode ${type} not implementedd yet`)); | ||
} | ||
@@ -103,2 +109,5 @@ } | ||
} | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
@@ -111,9 +120,15 @@ }); | ||
// make this better | ||
(0, exports.getSecret)(server, publicKeySecret).then((publicKey) => { | ||
(0, exports.getSecret)(server, publicKeySecret) | ||
.then((publicKey) => { | ||
if (publicKey) { | ||
if (type === 'jwt') { | ||
jwtDecode(resolve, reject, cleanCarriageReturn(value), publicKey); | ||
try { | ||
jwtDecode(resolve, reject, cleanCarriageReturn(value), publicKey); | ||
} | ||
catch (err) { | ||
reject(err); | ||
} | ||
} | ||
else { | ||
console.error(`decode ${type} not implementedd yet`); | ||
console.error(`decode ${type} not implemented yet`); | ||
} | ||
@@ -124,2 +139,5 @@ } | ||
} | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
@@ -126,0 +144,0 @@ }); |
{ | ||
"name": "@based/server", | ||
"version": "2.8.4", | ||
"version": "2.8.5", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
340111
5412