Skip to content

Commit

Permalink
eslint imrovements
Browse files Browse the repository at this point in the history
  • Loading branch information
stormwin committed Dec 4, 2020
1 parent e38fe80 commit 47aada7
Show file tree
Hide file tree
Showing 6 changed files with 910 additions and 21 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"es2021": true,
"node": true
},
"extends": "eslint:recommended",
"extends": [
"eslint:recommended",
"plugin:mocha/recommended",
"prettier"
],
"parserOptions": {
"ecmaVersion": 12
},
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
.vscode
13 changes: 13 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"trailingComma": "all",
"tabWidth": 4,
"useTabs": true,
"semi": true,
"singleQuote": true,
"arrowParens": "avoid",
"bracketSpacing": true,
"endOfLine": "auto",
"insertPragma": false,
"printWidth": 140,
"quoteProps": "as-needed"
}
30 changes: 12 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,23 @@ const pause = require('pause'),
jwt = require('jsonwebtoken'),
JWTVerify = promisify(jwt.verify).bind(jwt);

const headerName = (requestArg) => {
const headerName = requestArg => {
return requestArg.split('').reduce((memo, ch) => {
return memo + (ch.toUpperCase() === ch ? '-' + ch.toLowerCase() : ch);
}, 'x' + (requestArg.charAt(0) === requestArg.charAt(0).toUpperCase() ? '' : '-'));
};

/**
* `JwtStrategy` class.
*
*/
* `JwtStrategy` class.
*
*/

class JwtStrategy extends Strategy {

/**
* `JwtStrategy` constructor.
*
* @api public
*/
* `JwtStrategy` constructor.
*
* @api public
*/
constructor(options) {
super();
options = options || {};
Expand All @@ -37,9 +36,8 @@ class JwtStrategy extends Strategy {
maxAge: options.maxAge || 86400,
algorithms: options.algorithms || 'HS256',
requestKey: options.requestKey || 'user',
requestArg: options.requestArg || 'accessToken'
requestArg: options.requestArg || 'accessToken',
};

}

/**
Expand All @@ -54,7 +52,7 @@ class JwtStrategy extends Strategy {
* @param {Object} req
* @param {Object} options
* @api protected
*/
*/
async authenticate(req, options) {
if (!req._passport) {
return this.error(new Error('passport.initialize() middleware not in use'));
Expand All @@ -74,15 +72,12 @@ class JwtStrategy extends Strategy {
if (token) {
try {
payload = await JWTVerify(token, options.secret, options);
// eslint-disable-next-line no-empty
} catch (e) {

}
// eslint-disable-next-line no-empty
} catch (e) {}
}

const su = payload.user;
if ((su || su === 0) && (payload.exp > Date.now() || !payload.exp)) {

const paused = options.pauseStream ? pause(req) : null;
req._passport.instance.deserializeUser(su, req, (err, user) => {
if (err) {
Expand Down Expand Up @@ -111,7 +106,6 @@ class JwtStrategy extends Strategy {
}
}


/**
* Expose `JwtStrategy`.
*/
Expand Down
Loading

0 comments on commit 47aada7

Please sign in to comment.