Skip to content

Commit 7d561a6

Browse files
committed
Prettier added.
1 parent d1b98fb commit 7d561a6

File tree

9 files changed

+215
-143
lines changed

9 files changed

+215
-143
lines changed

.eslintrc.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"extends": [
3+
"prettier",
34
"eslint:recommended",
45
"plugin:node/recommended"
56
],
@@ -10,8 +11,12 @@
1011
"env": {
1112
"node": true,
1213
"mocha": true
13-
},
14+
},
15+
"plugins": [
16+
"prettier"
17+
],
1418
"rules": {
19+
"prettier/prettier": "error",
1520
"node/exports-style": ["error", "module.exports"],
1621
"node/file-extension-in-import": ["error", "always"],
1722
"node/prefer-global/buffer": ["error", "always"],

.npmignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.gitignore
22
node_modules
33
.project
4-
http-auth-koa.iml
4+
*.iml
55
.idea
66
.settings
77
_site
@@ -10,4 +10,5 @@ examples
1010
.travis.yml
1111
data
1212
.github
13-
.eslintrc.json
13+
.eslintrc.json
14+
.prettier.config.js

.prettier.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
tabWidth: 2,
3+
semi: true,
4+
singleQuote: true,
5+
trailingComma: 'es5',
6+
}

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,32 @@ $ npm install http-auth-passport
1919
## Usage
2020
```javascript
2121
// Express module.
22-
const express = require('express');
22+
const express = require("express");
2323

2424
// Authentication module.
25-
const auth = require('http-auth');
26-
const authPassport = require('http-auth-passport');
25+
const auth = require("http-auth");
26+
const authPassport = require("http-auth-passport");
2727
const basic = auth.basic({
28-
realm: "Simon Area.",
29-
file: __dirname + "/../data/users.htpasswd" // gevorg:gpass, Sarah:testpass
28+
realm: "Simon Area.",
29+
file: __dirname + "/../data/users.htpasswd" // gevorg:gpass, Sarah:testpass
3030
});
3131

3232
// Application setup.
3333
const app = express();
3434

3535
// Passport.
36-
const passport = require('passport');
36+
const passport = require("passport");
3737
passport.use(authPassport(basic));
3838

3939
// Setup route.
40-
app.get('/', passport.authenticate('http', { session: false }), (req, res) => {
41-
res.end(`Welcome to private area - ${req.user}!`);
40+
app.get("/", passport.authenticate("http", { session: false }), (req, res) => {
41+
res.end(`Welcome to private area - ${req.user}!`);
4242
});
4343

4444
// Start server.
4545
app.listen(1337, () => {
46-
// Log URL.
47-
console.log("Server running at http://127.0.0.1:1337/");
46+
// Log URL.
47+
console.log("Server running at http://127.0.0.1:1337/");
4848
});
4949
```
5050

examples/passport.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
// Express module.
2-
const express = require('express');
2+
const express = require("express");
33

44
// Authentication module.
5-
const auth = require('http-auth');
6-
const authPassport = require('../src/index');
5+
const auth = require("http-auth");
6+
const authPassport = require("../src/index");
77
const basic = auth.basic({
8-
realm: "Simon Area.",
9-
file: __dirname + "/../data/users.htpasswd" // gevorg:gpass, Sarah:testpass
8+
realm: "Simon Area.",
9+
file: __dirname + "/../data/users.htpasswd" // gevorg:gpass, Sarah:testpass
1010
});
1111

1212
// Application setup.
1313
const app = express();
1414

1515
// Passport.
16-
const passport = require('passport');
16+
const passport = require("passport");
1717
passport.use(authPassport(basic));
1818

1919
// Setup route.
20-
app.get('/', passport.authenticate('http', { session: false }), (req, res) => {
21-
res.end(`Welcome to private area - ${req.user}!`);
20+
app.get("/", passport.authenticate("http", { session: false }), (req, res) => {
21+
res.end(`Welcome to private area - ${req.user}!`);
2222
});
2323

2424
// Start server.
2525
app.listen(1337, () => {
26-
// Log URL.
27-
console.log("Server running at http://127.0.0.1:1337/");
28-
});
26+
// Log URL.
27+
console.log("Server running at http://127.0.0.1:1337/");
28+
});

package-lock.json

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
"url": "http://github.com/http-auth/http-auth-passport/issues"
2727
},
2828
"devDependencies": {
29+
"eslint-config-prettier": "^6.10.0",
30+
"eslint-plugin-prettier": "^3.1.2",
31+
"prettier": "^1.19.1",
2932
"chai": "^4.2.0",
3033
"eslint": "^6.8.0",
3134
"eslint-plugin-node": "^11.0.0",

src/index.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,38 @@
22

33
// Imports.
44
// eslint-disable-next-line node/no-unpublished-require
5-
const passport = require('passport');
6-
const util = require('util');
5+
const passport = require("passport");
6+
const util = require("util");
77

88
// Define strategy.
99
function HttpStrategy(auth) {
10-
this.name = 'http';
11-
this.authentication = auth;
10+
this.name = "http";
11+
this.authentication = auth;
1212

13-
passport.Strategy.call(this);
13+
passport.Strategy.call(this);
1414
}
1515

1616
// Inherit basic strategy.
1717
util.inherits(HttpStrategy, passport.Strategy);
1818

1919
// Define auth method.
20-
HttpStrategy.prototype.authenticate = function (req) {
21-
let self = this;
20+
HttpStrategy.prototype.authenticate = function(req) {
21+
let self = this;
2222

23-
// Is auth.
24-
this.authentication.isAuthenticated(req, (result) => {
25-
if (result instanceof Error) {
26-
self.error(result);
27-
} else if (!result.pass) {
28-
let header = self.authentication.generateHeader(result);
29-
self.fail(header);
30-
} else {
31-
self.success(result.user);
32-
}
33-
});
23+
// Is auth.
24+
this.authentication.isAuthenticated(req, result => {
25+
if (result instanceof Error) {
26+
self.error(result);
27+
} else if (!result.pass) {
28+
let header = self.authentication.generateHeader(result);
29+
self.fail(header);
30+
} else {
31+
self.success(result.user);
32+
}
33+
});
3434
};
3535

3636
// Export.
37-
module.exports = (auth) => {
38-
return new HttpStrategy(auth);
39-
};
37+
module.exports = auth => {
38+
return new HttpStrategy(auth);
39+
};

0 commit comments

Comments
 (0)